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 8647631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:06:58+00:00 2026-06-12T13:06:58+00:00

I want something that provide: std::list head; std::list::node node; while (node = head->next) {

  • 0

I want something that provide:

std::list head;
std::list::node node;
while (node = head->next) {
    do something with this node
};

It is rather weird to me that a list does not have a next pointer.

  • 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-12T13:06:59+00:00Added an answer on June 12, 2026 at 1:06 pm

    The actual implementation of the list is hidden. Since the standard dictates the the insertion and erasion of an element at a given position should be possible in constant time we can assume that something like a node is going to be used:

    23.3.5 Class template list [list]

    23.3.5.1 Class template list overview [list.overview]

    A list is a sequence container that supports bidirectional iterators and allows constant time insert and erase operations anywhere within the sequence, with storage management handled automatically. Unlike vectors (23.3.6) and deques (23.3.3), fast random access to list elements is not supported, but many algorithms only need sequential access anyway.

    However, the important thing about C++ container is that they all provide the same interface to actually traverse the content: iterators:

    for(std::list<double>::iterator it = list.begin(); it != list.end(); ++it){
       *it += 3.0; // add 3.0 to each element
    }
    

    If you think about the list as a C-style object with

    struct node{
        struct node * next;
        struct node * prev;
        double value;
    };
    
    struct list{
        struct node * first;
        struct node * last;
    }
    

    the loop above is somewhat equivalent to

    for(struct node * it = list.first; it != list.last + 1; it = it->next){
       *it += 3.0; // add 3.0 to each element
    }
    

    However, things like it = it->next are hidden in the actual implementation of the std::list::iterator. Since they provide an almost* unified interface for all classes you should learn to use them.

    * Some do actually provide a little bit more functionality than others, for example RandomAccessIterators vs. BidirectionalIterators, but this is something you will learn later.

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

Sidebar

Related Questions

I am not even sure how to ask this question. I want something that
I want to make something that makes much sense, but I think its not
this is something that i don't want to program, but i was looking for
I want something that will receive me the processes details, like I receive with
I want something to put in my .htaccess file that will hide the .php
Q1. I want to grep something like that: grep -Ir --exclude-dir=some*dirs my-text ~/somewhere but
I want to prompt the user that something special has happened, so I want
What a want to do is something like that: declare @id int set @id
I want to have something on my site that follows the mouse around, sort
I want to have a route that looks something like: www.abc.com/companyName/Controller/Action/Id However, all the

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.