Rearrange linked list in increasing order (Sort linked list)

Given a linked list, write a function to rearrange its nodes so they are sorted in increasing order. In other words, sort linked list.


We can use SortedInsert() function to sort linked list. We start with an empty result list. Iterate through the source list and SortedInsert() each of its nodes into the result list. Be careful to note the .next field in each node before moving it into the result list.


Download   Run Code


2 -> 3 -> 4 -> 6 -> 8 -> 9 -> null


Thanks for reading.

Please use ideone or C++ Shell or any other online compiler link to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂

Get great deals at Amazon

Leave a Reply

Notify of