-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
84 lines (79 loc) · 1.55 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "Digraph.h"
#include "BreadthDirectedFirstPaths.h"
#include "DirectedCycle.h"
#include <fstream>
#include <iostream>
#include <cstdio>
// Digraph test
void digraph_main() {
using namespace std;
ifstream inFile;
inFile.open("tinyDG.txt");
// inFile.open(argv[1]);
if (!inFile.is_open()) {
cerr << "File not opened!" << endl;
exit(1);
}
Digraph G(inFile);
Digraph H;
H = G;
cout << H << endl;
}
// BreadthDirectedFirstPaths test
void BDFP_main() {
using namespace std;
ifstream inFile;
inFile.open("tinyDG.txt");
// inFile.open(argv[1]);
if (!inFile.is_open()) {
cerr << "File not opened!" << endl;
exit(1);
}
Digraph G(inFile);
cout << G << endl;
// int s = 3;
int s;
cout << "Start: ";
cin >> s;
BreadthFirstDirectedPaths copy(G, s);
BreadthFirstDirectedPaths bfs;
bfs = copy;
for (int v = 0; v < G.V(); v++) {
if (bfs.hasPathTo(v)) {
printf("%d to %d (%d): ", s, v, bfs.distTo(v));
for (int x : bfs.pathTo(v)) {
if (x == s) cout << x;
else cout << "->" << x;
}
cout << endl;
}
else {
printf("%d to %d (-): not connected\n", s, v);
}
}
}
// Directed Cycle test
void DC_main() {
using namespace std;
ifstream inFile;
inFile.open("tinyDG.txt");
// inFile.open(argv[1]);
if (!inFile.is_open()) {
cerr << "File not opened!" << endl;
exit(1);
}
Digraph G(inFile);
DirectedCycle finder(G);
if (finder.hasCycle()) {
cout << "Cycle: ";
for (int v : finder.cycle())
cout << v << " ";
cout << endl;
}
else
cout << "No cycle" << endl;
}
int main(int argc, char* argv[]) {
DC_main();
return 0;
}