I have a few questions regarding lists. First, here is my code:
#include <iomanip>
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
struct node {
int x;
node *next;
};
void main()
{
node *root;
node *curr;
int exit = 0;
string temp;
root = new node;
root->next = 0;
curr = root;
cout << "Please enter the root number: ";
cin >> root->x;
for( int i=0; i<10; i++)//Will promt user to enter numbers
{
cout << "Enter string name for new node: ";
cin >> temp;
}
if (curr != 0)//Used for traversing the LL and outputting
{
while (curr->next != 0)
{
cout << curr->x;
curr = curr->next;
}
}
}
I would like the user to be prompted to enter a number in the for loop to be added on to the first node. But I am confused on creating more nodes past the root. Do they have to have different names for each node? I see where I created a new node named root. Would I have to do that for each and every node? If I do, can I have the user input a name for that node and have the program write in that name?