Thread: Questions on Linked Lists

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    5

    Questions on Linked Lists

    Hello,

    I have finished reading Lesson 15 on Linked Lists. There are some questions to ask about the code given in Lesson 15.

    The first is this section of code:

    struct node
    {
    int x; node *next;
    };

    For the *next pointer, is it in charge of pointing to another node? In Linked Lists, a node means another identical structure right?

    The second ques is this section of code:

    root->next = NULL;

    Is it compulsary to initialize the pointer of the first node to NULL each time?

    The third question:

    while(conductor->next != NULL)
    conductor = conductor -> next;

    Earlier on, the conductor pointer points to root (the first node). And the *next pointer was already set to NULL earlier. So it seems that the while loop will never run at all. Is this correct?

    Besides, what does this entire while loop do? I am still not so sure even after reading the Lesson explanations.

    Lastly, what is the whole idea of Linked Lists? Is it a continuous replication of a structure until a NULL is encountered?

    That's all......the question is rather long but thanks for your time.
    Please reply quickly if you can......thanks![CODE]

  2. #2
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    For the *next pointer, is it in charge of pointing to another node? In Linked Lists, a node means another identical structure right?

    Yeah... it points to another node. And I'm not sure if they're always called nodes, but I think it could be possible (all these books of mine can't be wrong).

    Is it compulsary to initialize the pointer of the first node to NULL each time?

    Would seem to be. I would initialize the pointer of each newly created node to NULL though so when searching through, I can stop when I hit NULL.

    Earlier on, the conductor pointer points to root (the first node). And the *next pointer was already set to NULL earlier. So it seems that the while loop will never run at all. Is this correct?

    I would assume that when a new node is added, the root would be updated.

    Besides, what does this entire while loop do?

    It basically jumps down the list until the next object is NULL.

    Lastly, what is the whole idea of Linked Lists? Is it a continuous replication of a structure until a NULL is encountered?

    It's a type of storage container with certain advantages and disadvantages.

    The biggest advantage that I see is that it allows new elements to be inserted/added almost instantly (whereas with arrays, all the elements below the one being added would have to be shifted down).

    The biggest disadvantage is that you can't do random access. You have to jump down the nodes basically one at a time to reach the desired node.
    Last edited by Frobozz; 11-29-2003 at 01:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  2. Question On Linked Lists
    By Zildjian in forum C Programming
    Replies: 8
    Last Post: 10-23-2003, 11:57 AM
  3. How to use Linked List?
    By MKashlev in forum C++ Programming
    Replies: 4
    Last Post: 08-06-2002, 07:11 AM
  4. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM
  5. Linked Lists -- Again!!! Help!!
    By Leeman_s in forum C++ Programming
    Replies: 4
    Last Post: 01-22-2002, 08:27 PM