Jump to content
  • Advertisement
Sign in to follow this  
Denzin

Sorting linked lists

This topic is 3300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, im just wondering what method of sorting would be efficient for nodes in a doubly linked list to be sorted by their integer elements in ascending order?

Share this post


Link to post
Share on other sites
Advertisement
Usually the method provided by the standard library of your language.

In a purely theoretical situation, if the list is almost sorted, insertion sort gets the best complexity. Otherwise, quicksort and merge sort are fairly good choices.

Share this post


Link to post
Share on other sites
I'll second Merge Sort.

Quicksort is slightly easier to implement, but has an awful (n^2) worst-case (which can potentially be abused by hostile users).

However, if you're doing anything other than inserting once in bulk prior to a single sort you'd be much better off with a tree of some form, efficiency (and algorithmic-complexity) wise. Of course, trees are far harder to implement.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!