I have been studying linked list tutorial. I want to add a new node to the begining of my linked list but I am making a mistake.
Can anyone show me what is wrong with my code?
Output should be like this
using namespace std;
node* root; //head point to first node
node* conductor; //pointer that moves node by node
root=new node; //dynamicly creating a new node and point to head
root->number=5; //first number in my list
conductor=root; //set conductor to root
if (conductor!=0) //check if there is a node in the list
while(conductor->next!=0) //go to the end of the list
conductor->next=new node; //create a new node
conductor=conductor->next; //set conductor to new node
conductor->number=10; //set seconds node number to 10
conductor->next=0; //set node next pointer to the NULL
conductor->next=new node; //create third node to put it the beginning of the list
conductor->number=1; //set third number to 1
conductor->next=root; //set the next part of the new node equal to root, which makes it point to the first node in the list ????
conductor=root; //set root to point to the new node ???
if (conductor->next!=0) //print list
1 5 10