question regarding linked lists.

This is a discussion on question regarding linked lists. within the C++ Programming forums, part of the General Programming Boards category; there is a linked list with 3 nodes, the nodes being 1 , 2 , and 3. 3 is the ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    13

    question regarding linked lists.

    there is a linked list with 3 nodes, the nodes being 1 , 2 , and 3. 3 is the head node. is it possible to keep a pointer at the tail node, 1, and then insert a node to the back of the tail, making the new node the tail node?

    for example, if i wanted to add a 0 to the back of the list, i can then put 0 behind 1. if it's possible, would i have to put 0 in the place of 1 and then shift the rest of the nodes up, or can i create a brand new node and place it right behind 1?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    can i create a brand new node and place it right behind 1?
    that would be a way.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    A linked list normally works with pointers between nodes. So to insert to the back, you'd need to make the last node point to the new node and then make the new node last.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question regarding comparing two linked lists
    By cyberfish in forum C++ Programming
    Replies: 2
    Last Post: 08-23-2007, 05:28 AM
  2. Linked Lists Question
    By panfilero in forum C Programming
    Replies: 4
    Last Post: 11-22-2005, 01:33 AM
  3. Linked Lists Question
    By SlyMaelstrom in forum C++ Programming
    Replies: 12
    Last Post: 11-12-2005, 12:03 PM
  4. eof in fstream & singly linked lists
    By mazo in forum C++ Programming
    Replies: 3
    Last Post: 06-03-2002, 10:50 AM
  5. doubly linked lists
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2001, 07:25 PM

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