-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBSF_Graph.cpp
More file actions
37 lines (35 loc) · 760 Bytes
/
BSF_Graph.cpp
File metadata and controls
37 lines (35 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;
int main()
{
queue<int> q;
int node;
int i = 1;
int visited[7] = {0, 0, 0, 0, 0, 0, 0};
int a[7][7] = {
{0, 1, 1, 1, 0, 0, 0},
{1, 0, 1, 0, 0, 0, 0},
{1, 1, 0, 1, 1, 0, 0},
{1, 0, 1, 0, 1, 0, 0},
{0, 0, 1, 1, 0, 1, 1},
{0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 1, 0, 0}};
cout << i;
visited[i] = 1;
q.push(i);
while (!q.empty())
{
int node = q.front();
q.pop();
for (int j = 0; j < 7; j++)
{
if (a[node][j] == 1 and visited[j] == 0)
{
cout << j;
visited[j] = 1;
q.push(j);
}
}
}
return 0;
}