Esempio n. 1
0
 /// <summary>
 /// 创建一个顶点排序对象 生成顶点线性队列
 /// </summary>
 /// <param name="g"></param>
 public DepthFirstOrder(GraphDigraph g)
 {
     // 初始markeds 数组
     this.markeds = new bool[g.countV()];
     // 初始化 reversePost stack 栈
     this.reversePostStack = new StackList <int>();
     // 遍历图中的每一个顶点,让每一个定点做作为入口,完成一次深度优先搜索
     for (int v = 0; v < g.countV(); v++)
     {
         if (!this.markeds[v])
         {
             dfs(g, v);
         }
     }
 }
Esempio n. 2
0
        public GraphDirectedCyle(GraphDigraph g)
        {
            // 初始化 markeds 数组
            this.markeds = new bool[g.countV()];
            // 初始化 hasCycleBool
            this.hasCycleBool = false;
            //初始化onStack
            this.onStack = new bool[g.countV()];

            // 找到图中每一个顶点 让每一个顶点作为入口调用一次 dfs 函数
            for (int v = 0; v < g.countV(); v++)
            {
                // 如果当前顶点 还没有搜索过 则调用dfs搜索
                if (!this.markeds[v])
                {
                    dfs(g, v);
                }
            }
        }