-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path22.2.cpp
67 lines (51 loc) · 1.29 KB
/
22.2.cpp
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
64
65
66
67
#include "22.2.h"
#include "../print.h"
using namespace CLRS::CH22;
int main() {
print(string("22.2 Breadth-first search"));
cout << "Initialize an undirected graph as Figure 22.3\n";
Graph G;
Vertex* r = new Vertex("r");
Vertex* s = new Vertex("s");
Vertex* t = new Vertex("t");
Vertex* u = new Vertex("u");
Vertex* v = new Vertex("v");
Vertex* w = new Vertex("w");
Vertex* x = new Vertex("x");
Vertex* y = new Vertex("y");
G.V.push_back(r);
G.V.push_back(s);
G.V.push_back(t);
G.V.push_back(u);
G.V.push_back(v);
G.V.push_back(w);
G.V.push_back(x);
G.V.push_back(y);
G.Adj[r].push_back(v);
G.Adj[r].push_back(s);
G.Adj[s].push_back(w);
G.Adj[s].push_back(r);
G.Adj[t].push_back(x);
G.Adj[t].push_back(w);
G.Adj[t].push_back(u);
G.Adj[u].push_back(y);
G.Adj[u].push_back(x);
G.Adj[u].push_back(t);
G.Adj[v].push_back(r);
G.Adj[w].push_back(t);
G.Adj[w].push_back(x);
G.Adj[w].push_back(s);
G.Adj[x].push_back(y);
G.Adj[x].push_back(w);
G.Adj[x].push_back(u);
G.Adj[x].push_back(t);
G.Adj[y].push_back(x);
G.Adj[y].push_back(u);
cout << "\nPerform BFS(G, s)\n";
bfs(G, s);
printGraph(G);
cout << "\nPerform PRINT-PATH(G, s, y)\n";
printPath(G, s, y);
cout << "\n\nPerform PRINT-PATH(G, s, t)\n";
printPath(G, s, t);
}