Thread: linked list

  1. #1
    Registered User
    Join Date
    Oct 2017
    Posts
    4

    linked list

    Code:
     struct node* AppendNode(struct node** headRef, int num) {
      struct node* current = *headRef;
       // special case for the empty list
       if (current == NULL) {
       Push(headRef, num);   ->why not use & in front of headref?
       } else {
       // Locate the last node
       while (current->next != NULL) {
       current = current->next;
       }
       // Build the node after the last node
       Push(&(current->next), num);
       }
       }
    i tried to practice linked list, this is code to add node using push, but i was confuse in this part, Push(headRef, num);

    ,in here why not using ampersand for &headref? if the argument is only headref, is it only copy the pointer to the push function?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,070
    Notice that headRef is a pointer to a pointer to struct Node.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 09-22-2013, 10:34 PM
  2. Declaring linked list inside linked list
    By blueboyz in forum C Programming
    Replies: 33
    Last Post: 04-20-2012, 10:13 AM
  3. single linked list to double linked list (help)
    By Countfog in forum C Programming
    Replies: 8
    Last Post: 04-29-2008, 08:04 PM
  4. singly linked list to doubly linked list
    By t48j in forum C Programming
    Replies: 3
    Last Post: 03-23-2005, 06:37 PM
  5. Replies: 6
    Last Post: 03-02-2005, 02:45 AM

Tags for this Thread