Thread: Pointers Sort?

  1. #1
    Registered User
    Join Date
    Nov 2001

    Pointers Sort?

    I need to sort through a linked list node consisting of an Integer and a pointer to the next Node without moving the elements themselves but by rearranging the pointers I haven't found a way to do this in any textbooks and have no idea where to start can anyone out there help?

  2. #2
    Do you want to sort a completely unsorted list, or insert a new node?

    to insert a node, just find the node that is before the new node, and the one after, by running through the list until you find that the node is greater than the new node. then update the pointers of the previous node to the new nodes position, and set the new node's pointer to the previous nodes old pointer value.

    if you need to sort a completely unsorted list, you'll have to use a recursive algorithm to check each node, until you find the next one, then set that nodes position to the last nodes pointer.

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    What you, summed up, have to do is just work through the linked list and then test with an if-else statement and the insert if 'x'<'y'. If you would like code, I will be more than happy to give it, but it is quite lengthy so tell me if you want it.

    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. pointers and vectors
    By rwmarsh in forum C++ Programming
    Replies: 6
    Last Post: 04-02-2006, 12:06 AM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM