摘要: 判断一个图是否为无环图: 完整代码 public class Cycle { private boolean[] marked; private int[] edgeTo; private Stack<Integer> cycle; /** * Determines whether the undi 阅读全文
posted @ 2021-01-20 16:11 wangheq 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 使用深度优先搜索查找图中的连通分量:思想就是在深度优先搜索的基础上,在加上一个连通分量的数值标识( count),用于统计有几个连通分量。 public class CC { private boolean[] marked; // marked[v] = has vertex v been mar 阅读全文
posted @ 2021-01-20 15:13 wangheq 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 广度优先搜索代码: public class BreadthFirstPaths { private static final int INFINITY = Integer.MAX_VALUE; private boolean[] marked; // marked[v] = is there an 阅读全文
posted @ 2021-01-20 12:14 wangheq 阅读(115) 评论(0) 推荐(0) 编辑
摘要: 深度优先搜索的代码: public class DepthFirstSearch { private boolean[] marked; // marked[v] = is there an s-v path? private int count; // number of vertices con 阅读全文
posted @ 2021-01-20 11:28 wangheq 阅读(126) 评论(0) 推荐(0) 编辑