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.
Lets say the next node is null, by the if statement above it only creates the node itself, puts the data in it and returns it. how then if the return is back to that line does the next node know what the previous node is? the
head->next->prev = head;
is absolutely necessary unless you want to start from the head again and make sure all the double links are correct. If it goes to the else if statement yes it is superflouous but for the total possibility of all cases being correct this is needed.
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →
Lets say the next node is null, by the if statement above it only creates the node itself, puts the data in it and returns it. how then if the return is back to that line does the next node know what the previous node is? the
is absolutely necessary unless you want to start from the head again and make sure all the double links are correct. If it goes to the else if statement yes it is superflouous but for the total possibility of all cases being correct this is needed.