-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
69 lines (47 loc) · 2.36 KB
/
Copy pathMain.java
File metadata and controls
69 lines (47 loc) · 2.36 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
public class Main {
public static void main(String[] args) {
test1();
}
public static void test1() {
System.out.println("\n------------1-INITIAL-----------");
Graph g = new Graph("graph.txt");
System.out.println(g);
System.out.println("\n\n=======TRAVERSALS=======");
System.out.println("\n------------2------------");
System.out.println("DFS:" + g.depthFirstTraversal());
System.out.println("BFS:" + g.breadthFirstTraversal());
System.out.println("Strongly Connected Components: \n" + g.stronglyConnectedComponents());
System.out.println("\n\n=======ADDITION-AND-REMOVAL-OF-VERTICES-AND-EDGES=======");
System.out.println("\n------------3-ADD(X)-----------");
g.insertVertex("X");
System.out.println(g);
System.out.println("\n\n------------4-ADD(JX-2)-&-ADD(XA-6)-&-ADD(MJ)----------");
g.insertEdge("j", "x", 2);
g.insertEdge("x", "a", 6);
g.insertEdge("M", "J", 5);
System.out.println(g);
System.out.println("Strongly Connected Components: \n" + g.stronglyConnectedComponents());
System.out.println("\n\n------------5-REMOVE(PL)------------");
g.removeEdge("p", "l");
System.out.println(g);
System.out.println("\n\n------------6-REMOVE(L)-----------");
g.removeVertex("l");
System.out.println(g);
System.out.println("\n\n=======SHORTEST-PATHS=======");
System.out.println("\n------------7------------");
Double shortestPath = g.shortestPath("a", "r");
System.out.println("Shortest Path from A to R: " + shortestPath);
System.out.println("\n------------8------------");
Double[][] shortestPaths = g.shortestPaths();
System.out.println("All-to-All Shortest Paths:");
System.out.println(g.printMatrix(shortestPaths));
System.out.println("\n\n=======CYCLE-DETECTION=======");
System.out.println("\n------------9------------");
if (g.cycleDetection())
System.out.println("Graph has a cycle");
else
System.out.println("Graph does not have a cycle");
System.out.println("\n------------10------------");
System.out.println("Strongly Connected Components: \n" + g.stronglyConnectedComponents());
}
}