隣接行列を取得し、頂点間の接続を決定するクラス ラボを完成させています。私のコードは実行されますが、正しい結果が得られません。
while ループの 2 番目の if ステートメントに問題があると思います。どんな助けでも大歓迎です。コードは以下のとおりです。
#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;
}
これは私が受け取っている出力です:
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
0 と 2 の間の別の接続が明らかに欠落しているのはどれですか?