Thread: How to sort a simple linked list using swap-sort method

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I corrected myself straight after I first posted. You must have taken over 5 minutes to post. I'm amazed you managed to see what I had written incorrectly. I realised immediately that I was thinking of one of the other sorts.

    You can definitely sort a doubly-linked list by swapping values. A number of coders who are used to array sorting try this as their first attempt at linked-list sorting. I certainly agree, it's a very bad idea and you've pointed out one reason why, but some people do it. The other reason is that you are stuck with algorithms that are O(n*n) because you have neither random access, nor tha ability to 'insert' items as you would with a list. I never intended to imply that swapping values would be the normal way of doing it.

    Edited for spelling this time.
    Last edited by iMalc; 01-18-2009 at 01:32 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 11-04-2006, 06:39 PM
  2. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  3. sort linked list using BST
    By Micko in forum C Programming
    Replies: 8
    Last Post: 10-04-2004, 02:04 PM
  4. Sort Linked List Algorithm.
    By xddxogm3 in forum C++ Programming
    Replies: 7
    Last Post: 10-13-2003, 11:05 PM
  5. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM