linked list inserting in a particular spot

This is a discussion on linked list inserting in a particular spot within the C Programming forums, part of the General Programming Boards category; Hey guys just wondering if someone could help me by just giving me some simple pseudocode to produce an algorithm. ...

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    linked list inserting in a particular spot

    Hey guys just wondering if someone could help me by just giving me some simple pseudocode to produce an algorithm.

    For example if i have values

    1
    2
    4
    5

    How would i implement the value 3 after the value 2 so that it is in order using a linked list example.

    So how would i insert the node in between the other nodes?

  2. #2
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335
    Firstly, you would find where the number fits. If it's 3: I think something like if it's greater than 1, 2 the loop should stop before 4 and insert the node after 2->next.

  3. #3
    C_newbie
    Join Date
    Oct 2005
    Location
    Greece
    Posts
    32
    read i
    for k=0; k<=i ++i
    k=k->next
    --------------------
    then insert the i after k
    you have just to adjust the ->s. Its like this
    k->next->prev=i
    i->next=k->next
    k->next=i
    i->prev=k
    AC/DC: Highway to Hell!
    No speed limit, no stop signs, nobody 's gonna slow me down!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. linked list question
    By mikeman in forum C Programming
    Replies: 1
    Last Post: 11-30-2008, 12:56 PM
  2. Adding directory/file names to a linked list
    By thoseion in forum C Programming
    Replies: 13
    Last Post: 12-08-2006, 12:13 PM
  3. Anyone good with linked list.....I am not....
    By chadsxe in forum C++ Programming
    Replies: 11
    Last Post: 11-10-2005, 01:48 PM
  4. Inserting new nodes in a sorted double linked list
    By carrja99 in forum C++ Programming
    Replies: 2
    Last Post: 03-07-2003, 07:34 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21