// 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; }
insert()
Delete()
this
node *p = new node ;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)