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

  • SEARCH
  • Home
  • 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 7730539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:14:57+00:00 2026-06-01T06:14:57+00:00

Feel free to edit the title, engrish can sometimes confuse instead of help. I

  • 0

Feel free to edit the title, engrish can sometimes confuse instead of help.

I have to make (and no I can’t change, this is the way it has to be) simple linked list. NO I can’t use STL or std::list. Most of it is done, on paper, but I seem to have a problem implementing a very basic cursor.

This is my Node within the list (part of it):

struct Node {
    int ap_nr;
    Node *next;
};

I want to go trough the list in my add node function:

void add_node (Node **begin, int ap_nr)
{
     stuff happens
}

This is how I call the function:

add_node(&(*begin), ap_nr);

I want to create a cursor that starts from begin (the head of my list) and goes trough every node using cursor->next until I reach the end (while (cursor->next!=0))

but I can’t simply say:

Node *cursor;
cursor = new Node;
cursor = begin;

Because this will simply overwrite cursor with begin, making my attempt invalid. I still have to make a pointer to begin and be able to call the STRUCT function “-> next”

How can I do this ?

* ALSO * How can I remember the previous Node ? can I do this:

Node *previous;
previous = new Node;
previous = &(*begin); // ?
  • 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-01T06:14:58+00:00Added an answer on June 1, 2026 at 6:14 am

    It sounds like you want to traverse the list in the add_node function. If so then try the following

    void add_node (Node **ppBegin, int ap_nr)
    {
      if (!ppBegin) {
        // Need to handle the case of bad user data here
      }
    
      // Traverse until we get the to the empty next value
      while ((*ppBegin)->next) {
        ppBegin = &((*ppBegin)->next);
      }
    
      // ppBegin now points to the address of where the new node should go
      Node* created = new Node();
      created->ap_nr = ap_nr;
      *ppBegin = created;
    }
    

    Note: To call this function initially you should just call it with add_node(&theListPointer).

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

Sidebar

Related Questions

If you have a better title for this question feel free to edit. For
Not entirely sure of a good title for this, feel free to edit it
I think I outsmarted myself this time. Feel free to edit the title also
I really have no idea what to title this so someone PLEASE feel free
Sorry for a poor title, feel free to edit. I can't understand what the
Sorry if this question will sound too chaotic, feel free to edit it. I
Edit This question has gone through a few iterations by now, so feel free
(couldn't think of a better title, feel free to edit it to a title
I'm not sure if I the title's correct, so feel free to edit it
Sorry for the confusing title, I couldnt explain it better. Feel free to edit

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.