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.
I'm doing the same thing, but I don't like how a new node is being allocated and initialized with every call to sortedInserted() with @calvin_cheng_cc's solution. Those Java guys have no concept of memory management (sorry!).
Also, this line above:
else if (data <= head.data) {
would be better as
else if (data < head.data) {
so that you do the insertion on finding first equality (as opposed to the last equality).
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →
I'm doing the same thing, but I don't like how a new node is being allocated and initialized with every call to sortedInserted() with @calvin_cheng_cc's solution. Those Java guys have no concept of memory management (sorry!). Also, this line above:
would be better as
so that you do the insertion on finding first equality (as opposed to the last equality).
This algorithm is the same one as used for: https://www.hackerrank.com/challenges/merge-two-sorted-linked-lists/forum
C solution: