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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:29:20+00:00 2026-05-27T05:29:20+00:00

I am working on Graphs and I created a Graph class and added #include

  • 0

I am working on Graphs and I created a Graph class and added #include <queue> to my code. If I write queue<int> MyQueue in main function it works well. But if I write the same code queue<int> MyQueue in my class Graph it gives me a runtime error. Waiting for your help.

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

class AdjListImp_Graph
{
    public: 
    vector<int> *array[8];
    vector<int> List[8];
    AdjListImp_Graph(){
        for(int i=1; i<8; i++)
            array[i] = &List[i];
    }
};

class AdjMatrixImp_Graph
{
    public:
    int AdjMatrix[7][7];
    queue<int> MyList; // !Having problem with this code!
    AdjMatrixImp_Graph(){
        for(int i=0; i<8; i++)
            for(int j=0; j<8; j++)
                AdjMatrix[i][j] = 0;
    }
};

int main (void)
{
    AdjListImp_Graph MyGraph_3a, MyGraph_3b, MyGraph_3c;
    MyGraph_3a.List[1].push_back(4);
    MyGraph_3a.List[2].push_back(4);
    MyGraph_3a.List[4].push_back(7);
    MyGraph_3a.List[6].push_back(3);
    MyGraph_3a.List[7].push_back(5);
    MyGraph_3b.List[1].push_back(2);
    MyGraph_3b.List[2].push_back(5);    MyGraph_3b.List[2].push_back(7);
    MyGraph_3b.List[4].push_back(3);    MyGraph_3b.List[4].push_back(6);
    MyGraph_3b.List[5].push_back(4);
    MyGraph_3b.List[6].push_back(1);    MyGraph_3b.List[6].push_back(7);
    MyGraph_3c.List[2].push_back(1);
    MyGraph_3c.List[3].push_back(4);    MyGraph_3c.List[3].push_back(6);
    MyGraph_3c.List[4].push_back(5);
    MyGraph_3c.List[5].push_back(2);
    MyGraph_3c.List[6].push_back(7);
    MyGraph_3c.List[7].push_back(2);
    /********************************************************************************************************/
    AdjMatrixImp_Graph My_Graph_3a, My_Graph_3b, My_Graph_3c;
    My_Graph_3a.AdjMatrix[1][4] = 1;
    My_Graph_3a.AdjMatrix[2][4] = 1;
    My_Graph_3a.AdjMatrix[3][2] = 1;
    My_Graph_3a.AdjMatrix[4][7] = 1; // 4'ten 7'ye yol   var.
    My_Graph_3a.AdjMatrix[6][3] = 1;
    My_Graph_3a.AdjMatrix[7][5] = 1;
    My_Graph_3b.AdjMatrix[1][2] = 1;
    My_Graph_3b.AdjMatrix[2][5] = 1;    My_Graph_3b.AdjMatrix[2][7] = 1;
    My_Graph_3b.AdjMatrix[4][3] = 1;    My_Graph_3b.AdjMatrix[4][6] = 1;
    My_Graph_3b.AdjMatrix[5][4] = 1;
    My_Graph_3b.AdjMatrix[6][1] = 1;    My_Graph_3b.AdjMatrix[6][7] = 1;
    My_Graph_3c.AdjMatrix[2][1] = 1;
    My_Graph_3c.AdjMatrix[3][4] = 1;    My_Graph_3c.AdjMatrix[3][6] = 1;
    My_Graph_3c.AdjMatrix[4][5] = 1;
    My_Graph_3c.AdjMatrix[5][2] = 1;
    My_Graph_3c.AdjMatrix[6][7] = 1;
    My_Graph_3c.AdjMatrix[7][2] = 1;

    system("pause");
    return EXIT_SUCCESS;
}
  • 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-05-27T05:29:21+00:00Added an answer on May 27, 2026 at 5:29 am

    In your initialization of AdjMatrixImp_Graph::AdjMatrix in the constructor of AdjMatrixImp_Graph, you are going beyond the array boundary. It possibly writes into the memory area of AdjMatrixImp_Graph::MyList, and corrupts its structure.

    Change the loops to for (int i;i<7;i++) for(int j;j<7;j++){.... Or you can use memset(AdjMatrix, 0, sizeof(AdjMatrix));

    Checking the main code suggests that the definition of AdjMatrix should be changed to AdjMatrix[8][8].

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

Sidebar

Related Questions

We have created an invite function at our site in JavaScript using the Graph
I'm currently working on a class that will create an x,y graph according to
I am working on a graph in WPF, in each section there are thousands
Working with a SqlCommand in C# I've created a query that contains a IN
I'm building a graph with core plot, that works fine except that I do
I've been working on a silverlight application which generates various graphs. It requires a
I'm using Google Chart ( http://code.google.com/apis/chart/ ) to produce some graphs for my company.
I am working in a graph using the great framework core-plot (in desktop OSX).
Having problems compiling this class. I'm working through a book on java and this
I need some sort of node-graph editor, that hopefully works on both Mac and

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.