How would I generate nodes inside a function for example I have a head node
Node * head = new Node;
now I want to generate nodes for as long as the for loop is running
void CreateList(Node * h)
{
for(int i = 0; i < 5; i++)
{
Node * n1 = new Node;
head -> next = n1;
}
}
somethig like this but it should keep adding nodes to the list and change the head each time so how would I do this
You want n1's next pointer to point to the previous first node.
n1->next = head->next;
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/