@@ -27,39 +27,95 @@ public static void main(String[] args) {
27
27
28
28
graph .dispaly ();
29
29
30
+ /* test 1 */
31
+
30
32
// System.out.println(graph.containsVertex("D"));
31
33
// System.out.println(graph.containsVertex("P"));
32
- //
34
+
33
35
// System.out.println(graph.numVertex());
34
36
// System.out.println(graph.numEdges());
35
37
//
36
38
// System.out.println(graph.containsEdge("A", "D"));
37
39
// System.out.println(graph.containsEdge("C", "D"));
38
40
// System.out.println(graph.containsEdge("C", "G"));
39
- //
41
+
40
42
// System.out.println("\nbefore: " + graph.numEdges());
41
43
// graph.removeEdge("E", "F");
42
44
// System.out.println("after: " + graph.numEdges());
43
- //
45
+
44
46
// graph.dispaly();
45
- //
47
+
48
+ /* test 2 */
49
+
46
50
// graph.addEdge("C", "F", 2);
47
51
// graph.dispaly();
48
- //
52
+
49
53
// System.out.println("before: " + graph.numVertex());
50
54
// graph.removeVertex("F");
51
55
// System.out.println("after: " + graph.numVertex());
52
56
// graph.dispaly();
53
57
54
- System .out .println ("tesing hasPath() method.." );
55
- HashMap <String , Boolean > processed = new HashMap <>();
56
- System .out .println (graph .hasPath ("A" , "F" , processed ));
58
+ /* test 3 */
59
+
60
+ // System.out.println("tesing hasPath() method..");
61
+ // HashMap<String, Boolean> processed = new HashMap<>();
62
+ // System.out.println(graph.hasPath("A", "F", processed));
63
+
64
+ // System.out.println(graph.hasPath("A", "E", new HashMap<String,
65
+ // Boolean>()));
66
+ // System.out.println(graph.hasPath("A", "G", new HashMap<String,
67
+ // Boolean>()));
68
+ // System.out.println(graph.hasPath("G", "C", new HashMap<String,
69
+ // Boolean>()));
70
+ // graph.removeEdge("D", "E");
71
+ // System.out.println(graph.hasPath("B", "F", new HashMap<String,
72
+ // Boolean>()));
73
+
74
+ /* test 4 */
75
+
76
+ // System.out.println("\ntesting Breadth First Search...\n");
77
+ // System.out.println(graph.bfs("A", "F")); // ADEF true
78
+
79
+ // // break the edge between D and E
80
+ // // graph.removeEdge("D", "E");
81
+ // // System.out.println(graph.bfs("A", "F")); // false
82
+
83
+ // // break the edge between A and D
84
+ // graph.removeEdge("A", "D");
85
+ // System.out.println(graph.bfs("A", "F")); // ABCDEF true
86
+
87
+ /* test 5 */
88
+
89
+ // System.out.println("\ntesting Depth First Search...");
90
+ // // System.out.println(graph.dfs("A", "F")); // ADEF true
91
+
92
+ // // test by replacing vertex name B to H in the Graph
93
+ // System.out.println(graph.dfs("A", "F")); // AHCDEF true
94
+
95
+ // /* test 6 */
96
+
97
+ // System.out.println("breadth first traversal...");
98
+ // graph.breadthFirstTraversal();
99
+ // System.out.println("\nremoving edge between D & E vertex and doing
100
+ // bft");
101
+ // graph.removeEdge("D", "E");
102
+ // graph.breadthFirstTraversal();
103
+
104
+ /* test 7 */
105
+
106
+ // System.out.println("depth first traversal...");
107
+ // graph.depthFirstTraversal();
108
+ // System.out.println("\nremoving edge between D & E vertex and doing
109
+ // dft");
110
+ // graph.removeEdge("D", "E");
111
+ // graph.depthFirstTraversal();
57
112
58
- System .out .println (graph .hasPath ("A" , "E" , new HashMap <String , Boolean >()));
59
- System .out .println (graph .hasPath ("A" , "G" , new HashMap <String , Boolean >()));
60
- System .out .println (graph .hasPath ("G" , "C" , new HashMap <String , Boolean >()));
61
- graph .removeEdge ("D" , "E" );
62
- System .out .println (graph .hasPath ("B" , "F" , new HashMap <String , Boolean >()));
113
+ /* test 8 */
114
+ System .out .println ("cyclic: " + graph .isCyclic ()); // true
115
+ graph .removeEdge ("C" , "D" );
116
+ System .out .println ("cyclic: " + graph .isCyclic ()); // true
117
+ graph .removeEdge ("F" , "G" );
118
+ System .out .println ("cyclic: " + graph .isCyclic ()); // false
63
119
64
120
}
65
121
}
0 commit comments