Linked list only outputs the root node and the last node entered
I have no idea why this program doesn't output the list, just the head of the list and the tail.
Code:
#include <iostream.h>
class node
{
public:
char *v;
node *next;
};
int main()
{
node *root;
node *x;
root = new node;
root->next = NULL;
root->v = "Start";
x = root;
for ( int i = 0; i < 4; i++ ) {
x->next = new node;
x = x->next;
x->next = NULL;
cout << "Enter your name: ";
cin.getline( x->v, 80 );
}
x = root;
if ( x != NULL )
{
int q = 1;
while ( x->next != NULL ) {
cout << x->v << " " << q++ << endl;
x = x->next;
}
}
return 0;
}