代码拉取完成,页面将自动刷新
package Chapter04DFSInAction.Section9CycleDetect;
import Chapter02GraphExpress.Graph;
import Chapter02GraphExpress.ReadGraph;
/***********************************************************
* @note : 检测无向图中的环 测试
* @author : l00379880 梁山广
* @version : V1.0 at 2019/8/8 10:18
***********************************************************/
public class Main {
private static void showResult(String filePath) {
Graph graph = new Graph(false);
ReadGraph.init(graph, filePath);
GraphDFSCycleDetect graphDFSCycleDetect = new GraphDFSCycleDetect(graph);
System.out.println("当前图中" + (graphDFSCycleDetect.hasCycle() ? "有" : "无") + "环");
}
public static void main(String[] args) {
// graph有环
String filePath = "src/main/java/Chapter04DFSInAction/Section9CycleDetect/graph.txt";
showResult(filePath);
// graph2.txt无环
filePath = "src/main/java/Chapter04DFSInAction/Section9CycleDetect/graph2.txt";
showResult(filePath);
}
}
/**
* 输出结果:
* <p>
* 顶点数V = 7, 边数E = 6
* 当前图中有环
* 顶点数V = 7, 边数E = 5
* 当前图中无环
* </p>
**/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。