forked from lsgwr/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
31 lines (27 loc) · 1016 Bytes
/
Main.java
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
package Chapter05BreadthFirstTraversal.Section6GraphBFSCycleDetect;
import Chapter02GraphExpress.Graph;
import Chapter02GraphExpress.ReadGraph;
public class Main {
private static void showResult(String filePath) {
Graph graph = new Graph(7, false);
ReadGraph.init(graph, filePath);
GraphBFSCycleDetect graphBFSCycleDetect = new GraphBFSCycleDetect(graph);
System.out.println("当前图中" + (graphBFSCycleDetect.hasCycle() ? "有" : "无") + "环");
}
public static void main(String[] args) {
// graph有环
String filePath = "src/main/java/Chapter05BreadthFirstTraversal/Section6GraphBFSCycleDetect/graph.txt";
showResult(filePath);
// graph2.txt无环
filePath = "src/main/java/Chapter05BreadthFirstTraversal/Section6GraphBFSCycleDetect/graph2.txt";
showResult(filePath);
}
}
/**
* 输出结果
* <p>
* 顶点数V = 7, 边数E = 6
* 当前图中有环
* 顶点数V = 7, 边数E = 5
* 当前图中无环
*/