linked list source code errors

This is a discussion on linked list source code errors within the C++ Programming forums, part of the General Programming Boards category; i recently was learning about linked lists using example code from this site. here is the code: Code: struct node ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    1

    linked list source code errors

    i recently was learning about linked lists using example code from this site.
    here is the code:
    Code:
    struct node
    {
      int x;
      node *next;
    };
    int main()
    {
      node *root; //This won't change, or we would lose the list in memory
      node *conductor; //This will point to each node as it traverses
    				   //the list
      root=new node; //Sets it to actually point to something
      root->next=NULL; //Otherwise it would not work well
      root->x=12;
      conductor=root; //The conductor points to the first node
      if(conductor!=NULL)
      {
        while(conductor->next!=NULL)
        {
          conductor=conductor->next;   
        }
      }
      conductor->next=new node; //Creates a node at the end of the list
      conductor=conductor->next; //Points to that node
      conductor->next=NULL; //Prevents it from going any further
      conductor->x=42;
    }
    i was wondering how / where do i edit this code so i can accept user input that then is placed in the list. i have tried various ways but it never works.

    also where do i put the code to print out the linked list
    Code:
    conductor=root;
    if(conductor!=NULL) //Makes sure there is a place to start
    {
      while(conductor->next!=NULL)
      {
        cout<<conductor->x;
        conductor=conductor->next;
      }
      cout<<conductor->x;
    }
    i am very confused can anyone help me out please.

    thanx
    Last edited by C++_Learner; 04-19-2002 at 02:31 AM.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    381
    Prehaps this thread might help you:
    http://www.cprogramming.com/cboard/s...threadid=13473
    If you own a piece of land and there is an volcano on it and it ruins a
    nearby town, do you have to pay for the property damage?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Not Saving Value as Int
    By bar338 in forum C Programming
    Replies: 4
    Last Post: 05-04-2009, 08:53 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  3. Linked List
    By silicon in forum C++ Programming
    Replies: 5
    Last Post: 07-21-2004, 08:47 PM
  4. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

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