Click here to Skip to main content
16,014,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
// list2peyvandi.cpp : Defines the entry point for the console application.
//
 //delete o inserte list peyvandi 2 tarafe

#include "stdafx.h"
#include<iostream>
using namespace std;

struct node 
{
	int data ;
	node *next ;
	node *prev;
};
	node *pred = NULL ;
	node *insert(node * , int )  ;
	void show() ;
	void Delete();




//void Delete()
//{
//	node *p = new node ;
//	if(pred == NULL || p == NULL )
//		return;
//	if( p == pred )
//	{
//		p ->next -> prev = NULL ;
//		pred = p -> next ;
//	}
//	else 
//	{
//		p -> prev -> next = p -> next ;
//		if(p ->next)
//			p -> next -> prev = p-> prev ;
//	}
//
//	delete p ;
//}
//void show()
//{
//
//    node *curPtr = pred ;
//	
//    while(curPtr)
//    {
//        cout<<curPtr->data<<endl;
//        curPtr = curPtr->next;
//	
//	}
//}
int main()
{
	node *pred , *cur ;
	int x ;
	cout << " create linked list " << endl ;
	do{
		cout << " enter data " << endl ;
		cin >> x ;
		if(pred == NULL)
			pred = insert(NULL,x);
		else
			cur = pred ;
			pred =  NULL ; 
			while(cur != NULL && x>cur->data)
			{
				pred = cur ;
				cur = cur ->next ;

			}
	if(insert(pred,x))
		cout<<"inset number"<<x;
	}while(x !=0);
	
	return 0;
}

node *insert(node *pred , int data)
{
	node *p = new node ;
	p->data=data;
	if(pred == NULL)
	{
		p ->next = pred ;
		p ->prev = NULL ;
		if(pred != NULL )
			pred -> prev = p ;
			pred = p ;
	}
	else
	{
		p -> prev = pred ;
		pred -> next = p -> next ;
		pred -> next -> prev = p ;
		pred ->next = p ;
	}
	return p;
}
Posted
Updated 24-Mar-11 21:50pm
v3
Comments
CPallini 24-Mar-11 6:48am    
No question.

1.) on insert() you get a bunch of circular references if n>1!
2.) on Delete() you have to deal with this not node *p = new node ;
Good luck.
 
Share this answer
 
No I/O in the code of list. If you do it, your Question can be considered. See my other Answer on the topic.
—SA
 
Share this answer
 
Comments
Richard MacCutchan 25-Mar-11 5:51am    
Unfortunately his/her response to comments seems to be to repost the same question over again. :(
Sergey Alexandrovich Kryukov 25-Mar-11 12:18pm    
I saw it.
--SA
yay hello 25-Mar-11 13:14pm    
now i put I/O in the main is it true ? i dont know what should i do ?
Sergey Alexandrovich Kryukov 25-Mar-11 14:06pm    
OK, put it in main. Abstract list from I/O.
I don't know how to help you more. You're not aware of basics.
--SA
You already posted this question once. If you need to modify it then please edit your original question.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Mar-11 15:23pm    
I demanded to remove I/O. It should be done to be considered. Instead, I see... this. Now I demanded it again...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900