You are viewing a single comment's thread. Return to all comments →
if(head==NULL) { DoublyLinkedListNode* temp=new DoublyLinkedListNode(data); head=temp; } else if(head->data>=data) { DoublyLinkedListNode* newnode= new DoublyLinkedListNode(data); newnode->prev=NULL; newnode->next=head; head->prev=newnode; head=newnode; } else { DoublyLinkedListNode* newnode=new DoublyLinkedListNode(data); DoublyLinkedListNode* temp=head; while(temp==NULL || temp->next->data<data) { if(temp->next->data>data || temp->next->next==NULL) { temp=temp->next; break; } temp=temp->next; } if(temp->next!=NULL) { DoublyLinkedListNode* t=temp; t=t->next; temp->next=newnode; t->prev=newnode; newnode->next=t; newnode->prev=temp; } else { temp->next=newnode; newnode->prev=temp; newnode->next=NULL; } } return head;
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 →