Wheee, time to draw a sweet paint picture!
*opens paint and starts doodling*
-see the picture below for reference to these code blocks....and the first block says Head Node...it's kinda unreadable-
Stage 1:
Code:
struct node
{
int id;
node* next;
};
int main()
{
node* head=new node();
return 0;
}
head is just a single node, not pointing to anything
Stage 2:
Code:
struct node
{
int id;
node* next;
};
int main()
{
node* head=new node();
head->next=new node();
return 0;
}
Now we have what is shown in Stage 2 of the image.
And now....we can do the same thing with Stage 3:
Code:
struct node
{
int id;
node* next;
};
int main()
{
node* head=new node();
head->next=new node();
node* nextNode=head->next;
nextNode->next=new node();
return 0;
}
And the problem with your code is that you can not assign a value to a function. Take the return value from the function and store it to a variable, and THEN assign the value.