-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphTestClient.java
More file actions
74 lines (60 loc) · 2.05 KB
/
GraphTestClient.java
File metadata and controls
74 lines (60 loc) · 2.05 KB
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
package Graph;
import java.util.*;
public class GraphTestClient {
public static void main(String[] args) {
/*Graph g = new Graph(13);
g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(0, 5);
g.addEdge(0, 6);
g.addEdge(3, 4);
g.addEdge(3, 5);
g.addEdge(4, 5);
g.addEdge(4, 6);
g.addEdge(7, 8);
g.addEdge(9, 10);
g.addEdge(9, 11);
g.addEdge(9, 12);
g.addEdge(11, 12);*/
Graph g = new Graph(6);
g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(0, 5);
g.addEdge(1, 2);
g.addEdge(2, 3);
g.addEdge(2, 4);
g.addEdge(3, 4);
g.addEdge(3, 5);
g.printGraph();
int s = 0;
// DepthFirstSearch search = new DepthFirstSearch(g, 0);
/* BreadthFirstSearch search = new BreadthFirstSearch(g, 0);
for (int i = 0; i < g.V(); i++) {
if (search.hasPathTo(i)) {
System.out.print(s + " to " + i + ": ");
for (int x : search.pathTo(i)) {
if (x == s) System.out.print(x);
else System.out.print("->" + x);
}
System.out.println();
}
}*/
/* ConnectedComponents cc = new ConnectedComponents(g);
int counts = cc.numberOfConnectedComponents();
System.out.println("Number of Components " + counts);
List<List<Integer>> components = new ArrayList<List<Integer>>();
for (int i = 0; i < counts; i++) {
List<Integer> list = new ArrayList<Integer>();
System.out.print("Component " + i + ": ");
for (int v = 0; v < g.V(); v++) {
if (cc.id(v) == i) {
list.add(v);
System.out.print(v + ", ");
}
}
System.out.println();
} */
Cycle c = new Cycle(g);
System.out.println(c.hasCycle());
}
}