We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
else
{ DoublyLinkedListNode* newnode=new DoublyLinkedListNode(data);
DoublyLinkedListNode* temp=head;
while(temp->next->data<data && temp->next!=NULL)
{
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;
}
What is wrong in this code?It does not work when the element is to be inserted at the end of the list
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →
DoublyLinkedListNode* sortedInsert(DoublyLinkedListNode* head, int data) {
}