im trying to output my bfs in this manner, showing the connections rather than the individual nodes:
input
0 1 1 0
1 0 0 0
1 0 0 1
0 0 1 0
output
(0,1)
(0,2)
(2,3)
rather than:
0
1
2
3
this is my code so far, the ??? indicate where im not sure what code to use.
void bfs(int matrix[MAXSIZE][MAXSIZE], int current, int n)
{
bool visited [MAXSIZE] = {false};
queue <int> q;
visited [current] = true;
q.push(current);
while (!q.empty())
{
current = q.front();
cout << "(" << ??? << "," << current << ")" << endl;
q.pop();
getAllAdjacent(matrix, current,visited,q, n);
}
}
void getAllAdjacent(int matrix[MAXSIZE][MAXSIZE], int current, bool visited[], queue <int> &q, int n)
{
// put all aunvisited vertices adjacent to current
// onto queue
for (int col= 0; col < n; col++)
if (matrix[current][col]>=1 && !visited[col])
{
q.push(col);
visited[col] = true;
}
}