-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
40 lines (30 loc) · 1.17 KB
/
Main.java
File metadata and controls
40 lines (30 loc) · 1.17 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
public class Main {
// 测试无权图最短路径算法
public static void main(String[] args) {
String filename = "testG.txt";
SparseGraph g = new SparseGraph(7, false);
ReadGraph readGraph = new ReadGraph(g, filename);
g.show();
// 比较使用深度优先遍历和广度优先遍历获得路径的不同
// 广度优先遍历获得的是无权图的最短路径
Path dfs = new Path(g,0);
System.out.print("DFS : ");
dfs.showPath(6);
ShortestPath bfs = new ShortestPath(g,0);
System.out.print("BFS : ");
bfs.showPath(6);
System.out.println();
filename = "testG1.txt";
SparseGraph g2 = new SparseGraph(13, false);
ReadGraph readGraph2 = new ReadGraph(g2, filename);
g2.show();
// 比较使用深度优先遍历和广度优先遍历获得路径的不同
// 广度优先遍历获得的是无权图的最短路径
Path dfs2 = new Path(g2,0);
System.out.print("DFS : ");
dfs2.showPath(3);
ShortestPath bfs2 = new ShortestPath(g,0);
System.out.print("BFS : ");
bfs.showPath(3);
}
}