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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:40:39+00:00 2026-05-27T21:40:39+00:00

Let’s say I have a: std::vector<std::list<Node> > And let’s say Node is: class Node

  • 0

Let’s say I have a:

std::vector<std::list<Node> >

And let’s say Node is:

class Node { 
    Node* next;
    int data;
};

The vector cells correspond to hash function values for fast look-ups. The idea is you insert your elements to the vector, but still chain them together with the Node-> next member. So you have a list where the elements can efficiently be looked up by key using a hash function to find the correct vector cell to start from.

Anyway, all that aside. My question is:

Can I have my Node::next pointers point to other nodes in a list (be it the same one, or another one from a different vector cell) without causing problems? I wasn’t sure if the standard library implementation of a list would allow this. I seem to be running into problems (my code’s not accessible here) and I wanted to see if this could be the cause.

  • 1 1 Answer
  • 1 View
  • 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-05-27T21:40:39+00:00Added an answer on May 27, 2026 at 9:40 pm

    If you want it to point to other nodes in the list, that’s totally doable, yes. However, I would propose a different design: a std::list<int> and a std::unordered_map<int, std::list<int>::iterator>, both members of a class who’s only purpose is to keep the two containers synchonized. This should be easier, safer, and faster than (my interpretation of) your current plan.

    Adding and removing objects to both lists is a breeze:

    std::unordered_map<int, std::list<int>::iterator> fast;
    std::list<int> linked;
    
    void add(int data) {
        fast[data] = linked.insert(linked.end(), data);
    };
    std::list<int>::iterator erase(std::list<int>::iterator iter) {
        fast.erase(*iter);
        return linked.erase(iter);        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let say that I have xml like this: <root> <node light=somevalue>message1</node> <node dark=somevalue>message2</node> <node>message3</node>
let's say i have this public class MyClass { public string myMessage { get;
Let's say I have the following classes: class Votable(models.Model): name = ... class Vote(models.Model):
Let's say we have the following: abstract class A; class B : public A;
Let's say I have a drive such as C:\ , and I want to

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.