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