You are viewing a single comment's thread. Return to all comments →
Node* SortedInsert(Node *head,int data) { Node *cur,*p; cur=head->next; Node temp=(Node)malloc(sizeof( Node)); temp->data=data; temp->next=NULL; temp->prev=NULL; if(temp->datadata) { temp->next=head; head->prev=temp; temp->prev=NULL; return temp; } while(cur!=head) { if((temp->data)<(cur->data)) { p=cur->prev; temp->next=cur; cur->prev=temp; p->next=temp; temp->prev=p; return head; } cur=cur->next; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →
Node* SortedInsert(Node *head,int data) { Node *cur,*p; cur=head->next; Node temp=(Node)malloc(sizeof( Node)); temp->data=data; temp->next=NULL; temp->prev=NULL; if(temp->datadata) { temp->next=head; head->prev=temp; temp->prev=NULL; return temp; } while(cur!=head) { if((temp->data)<(cur->data)) { p=cur->prev; temp->next=cur; cur->prev=temp; p->next=temp; temp->prev=p; return head; } cur=cur->next; } }