-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbfs_1.cc
More file actions
63 lines (43 loc) · 787 Bytes
/
bfs_1.cc
File metadata and controls
63 lines (43 loc) · 787 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "/home/icegpu/HK/HKTool.h"
#include <queue>
#include <vector>
using namespace std;
int number = 9;
int visit[9];
vector<int> a[10];
void bfsRun(int start){
queue<int> q;
q.push(start);
visit[start] = true;
while(!q.empty()){
int x = q.front();
q.pop();
cout << x << "\n";
for(int i = 0; i < a[x].size(); ++i){
int y = a[x][i];
if(!visit[y]){
q.push(y);
visit[y] = true;
}
}
}
}
void bfs_1(){
a[1].push_back(2);
a[2].push_back(1);
a[1].push_back(3);
a[3].push_back(1);
a[2].push_back(4);
a[4].push_back(2);
a[2].push_back(5);
a[5].push_back(2);
a[4].push_back(8);
a[8].push_back(4);
a[5].push_back(9);
a[9].push_back(5);
a[3].push_back(6);
a[6].push_back(3);
a[3].push_back(7);
a[7].push_back(3);
bfsRun(1);
}