Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8811077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:16:25+00:00 2026-06-14T03:16:25+00:00

I have a few questions regarding lists. First, here is my code: #include <iomanip>

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:16:27+00:00Added an answer on June 14, 2026 at 3:16 am

    To create more nodes past the root, just do the same thing:

     // assuming 'curr' points to end of list
     curr->next = new node;  // here's the new node
     curr = curr->next;      // update curr (if you want) to point to the newest node
     curr->next = 0;         // probably should be done in nodes ctor
    

    You would not “name” the new nodes, you just have “root” and “curr”. To find any one node, start at “root” and traverse to the one you want. Of course you could save ptrs to some nodes for faster access, but that would be specific to a particular application.

    Also in your current input loop:

    for( int i=0; i<10; i++)//Will promt user to enter numbers
    {
        cout << "Enter string name for new node: ";
        cin >> temp;
    }
    

    The user inputs a value 10 times, but it goes in ‘temp’ every time. So it keeps getting overwritten.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few questions regarding android source code download, repo / git. This
I have a few questions regarding Compact SQL. I am using VS C# 2008
I have a few questions regarding using socket IO with PHP and such, I
I am a newbie user of Frama-C and have a few questions regarding assertions
I'm very new to TDD world. I have a few questions regarding TDD. Do
I have a few basic questions regarding the syntax and usage of properties in
Although I have read a few previously answered questions regarding a similar issue, I
I have few questions about using lock to protect my shared data structure. I
I have few questions regarding HornetQ: What are differences between HornetQ core API and
I have few questions regarding safety and correctness of following hypothetical timer service: @Singleton

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.