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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:06:39+00:00 2026-06-04T08:06:39+00:00

I am completing a class lab which takes an adjacency matrix, and determines connectivity

  • 0

I am completing a class lab which takes an adjacency matrix, and determines connectivity among vertices. Although my code runs, it does not give the correct results.

I believe there is a problem with the the second if statement in my while loop. any help is greatly appreciated. Code is below:

#include "graph.h"
#include <assert.h>

using namespace std;

bool Graph::connected(int v,int w) {

    int visited[SIZE] ={0};

    if (v == w)         
        return adj_matrix[v][v];

    Queue<int> Q;      
    Q.Enqueue(v);      

    while (!Q.empty()) {
        int curr = Q.Dequeue();

        if (curr == w)
            return true;

        int z=0;         
        for (int i=0; i<SIZE; i++) {      
            if (adj_matrix[curr][z]==1 && visited[i]==false) {
                Q.Enqueue(z);
                visited[i]==true;
            }   
        }
    }
    return false;  
}

This is the output I am receiving:

0 0 1 0 
0 0 0 0 
0 0 0 0 
0 0 0 1 
vertex 0 is connected to vertices: 
vertex 1 is connected to vertices: 
vertex 2 is connected to vertices: 
vertex 3 is connected to vertices: 3 

Which is clearly missing another connection between 0 and 2 correct?

  • 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-04T08:06:41+00:00Added an answer on June 4, 2026 at 8:06 am

    Look closely at your use of the variables i and z. It appears that z is assigned the value 0, and never changed after that. You may want to try using more descriptive variable names to avoid this sort of confusion.

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

Sidebar

Related Questions

all i this is my code in notification class which i am calling after
I want to implement a class which its fields could change (add new fields)
Does making a class field volatile prevent all memory visibility issues with it in
I'm writing (well, completing) an extension of Java which will help role programming. I
I am completing a text based game for an intro to python class. It
I am in the middle of completing some code, I almost finished my code
When auto-completing a class name in Eclipse, e.g. if you type: ListI Tab A
I'm writing an MPI program for a parallel computing class. I've got the code
I have a game which have 5 class/level.Each class contain almost same variables.Now i
I am completing a lab assignment for school and get this error when I

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.