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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:48:31+00:00 2026-06-15T17:48:31+00:00

This question is a continuum from this one I have a vector of lists

  • 0

This question is a continuum from this one
I have a vector of lists in my Node class that are not being passed to other functions.

Here is the Node.h

#include "MyGraph.h"

//The Node Class will take the information from the graph class and
//convert the information into a format so we can perform DFS on our
//graph.

enum VertexState { White, Gray, Black };


class Node {
    private:
    string nodeId;
    VertexState status; //whether or not the vertex Node has been visited or not
    vector<Node> nodeList;
    vector<list<Node> > *edgeList;

public:
    Node(): nodeId(), status(){}

    //copy constructor
    Node(string vertex){
    nodeId=vertex;
    status = White;
    }
    ~Node(){}

   //Setter and Getter methods for our class variables
    void setId(string vertex){
       nodeId = vertex;
    }
    void setStatus(VertexState newStatus){
        status = newStatus;
    }

    string getNodeId(){
        return nodeId;
    }

    VertexState getStatus(){
        //status == White then it is not visited
        //status == Gray its being processed
        //status == Black then it has been visited
        return status;

    }


    vector<Node> getNodeList(){
        return nodeList;
    }
    vector<list<Node> > getEdgeList(){
        return *edgeList;
    }



    //create nodes from vertex list in the graph object
    void createNodeList(MyGraph graphObject){
        vector<string> vertexList;
        vertexList = graphObject.getVertexList();
        vector<string>::iterator it;
        vector<Node>placeNodeList;
        for (it = vertexList.begin(); it !=vertexList.end(); it++){
            Node newNode(*it);
            placeNodeList.push_back(newNode);
        }

        nodeList = placeNodeList;

        cout << "Size of initial nodeList: " << nodeList.size()<<endl;
    }


    //creates container for edge lists from the graph object
    void createEdgeList(MyGraph graphObject){
        vector<list<string> > newEdgeList;
        newEdgeList = graphObject.getEdgeList();



        vector<list<Node> > myEdgeList;


        vector<list<string> >::iterator it;
        for (it = newEdgeList.begin() ; it != newEdgeList.end(); it++) {
            list<string> edgeString;
            list<string>::iterator eIt;
            edgeString =*it;
            list<Node> edgeContainer; //creates a list container to be pushed on to our edgeList variable
            for (eIt = edgeString.begin(); eIt != edgeString.end(); eIt++) {
                Node newNode(*eIt);
                edgeContainer.push_back(newNode);
            }
            myEdgeList.push_back(edgeContainer);
        }
        edgeList = &myEdgeList;

        cout << "Size of intial edgeList: "<<edgeList->size() <<endl;




    }




    //The operational methods that will work on the Nodes of the graph
    vector<Node> dephtFirstSearch(Node vertex);//will determine if our graph is connected.
    vector<Node> DFS2(vector<Node> copyNodeList);
    bool isGraphConnected(vector<Node> nodeList);
    bool isEdgeConnected(Node vertex1, Node vertex2);//will determine if there is an edge between two nodes
    bool findElementaryCycles();
    void findArticulationPoints();
    void removeVertex(Node myNode, vector<Node>copyNodeList, vector<list<Node> >copyEdgeList);

    };

When I try to call vector edgeList in my other functions using:
edgeList->empty;
The function is empty when it shouldn’t be.
The createEdgeList function is called every time i need it to be used so its not empty.
How do I pass the data from my private variable to the functions?

  • 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-15T17:48:32+00:00Added an answer on June 15, 2026 at 5:48 pm
    vector<list<Node> > myEdgeList;    
    ...
    edgeList = &myEdgeList;
    

    You are storing a pointer to a local variable – this is at best undefined behavior.

    Why dont you make edgelist a normal vector and add to it directly in createEdgeList

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

Sidebar

Related Questions

Introduction I have a question coming from this one: Loop calling an asynchronous function
related (sort of) to this question. I have written a script that will loop
Not sure it is clear from this question title what I mean, so here
I have asked this question before with other adapters like SimpleAdapter but the solution
This continues from a previous question . I tried the suggested fix to check
This question is similar in concept to this one , except I see I
This question is related to another question I wrote: Trouble using DOTNET from PHP.
I have a method as follows (from a class than implements TBB task interface
Despite this being one of the best error messages I've ever seen (second only
This question is related to one I asked previously, see here . As a

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.