#include <iostream>
usingnamespace std;
struct nodeType{
int info;
nodeType *link;
};
void printList(nodeType *head)
{
nodeType *current = head;
if (head == NULL)
{
cout << "Empty list\n";
}
else{
while (current != NULL)
{
cout << current->info << " ";
current = current->link;
}
cout << endl;
}
}
int main()
{
nodeType *head = NULL; // 1
nodeType *current;
printList(head);
// 2: insert number 100 to as first node
current = new nodeType;
current->info = 100;
current->link = NULL;
head = current;
printList(head);
// 3: insert number 200 before number 100
current = new nodeType;
current->info = 200;
current->link = head;
head = current;
// 4: print link list from the beginning
//print the link list
//-------------------------
printList(head);
current = new nodeType;
current->info=300;
current->link = head;
head = current;
printList(head);
current = new nodeType;
current->info=400;
current->link = NULL;
head = current;
printList(head);
system("pause");
return 0;
}
The node with the value of 400 is the node that has to be last.. How would that work?