Exemplo n.º 1
0
        void Dfs(DirectedGraph g, int v)
        {
            onStack[v] = true;
            marked[v]  = true;
            foreach (var i in g.Adj(v))
            {
                if (HasCircle())
                {
                    return;
                }
                else if (!marked[i])
                {
                    edgeTo[i] = v;
                }
                else if (onStack[i])
                {
                    circle = new Stack <int>();
                    for (int j = v; j != i; j = edgeTo[j])
                    {
                        circle.Push(j);
                    }
                    circle.Push(i);
                    circle.Push(v);
                }
            }

            onStack[v] = false;
        }
Exemplo n.º 2
0
 void Dfs(DirectedGraph g, int v)
 {
     marked[v] = true;
     foreach (var i in g.Adj(v))
     {
         if (!marked[i])
         {
             Dfs(g, i);
         }
     }
 }
Exemplo n.º 3
0
 void Dfs(DirectedGraph g, int v)
 {
     pre.Enqueue(v);
     marked[v] = true;
     foreach (var i in g.Adj(v))
     {
         if (!marked[i])
         {
             Dfs(g, i);
         }
     }
     post.Enqueue(v);
     reversePost.Push(v);
 }