Exemplo n.º 1
0
 private void DFS(Digraph g, int v)
 {
     onStack[v] = true;
     marked[v]  = true;
     foreach (var w in g.Adj(v))
     {
         if (HasCycle())
         {
             return;
         }
         else if (!marked[w])
         {
             edgeTo[w] = v;
             DFS(g, w);
         }
         else if (onStack[w])
         {
             cycle = new Stack <int>();
             for (int x = v; x != w; x = edgeTo[x])
             {
                 cycle.Push(x);
             }
             cycle.Push(w);
             cycle.Push(v);
         }
         onStack[v] = false;
     }
 }
Exemplo n.º 2
0
 public void DFS(Digraph g, int v)
 {
     marked[v] = true;
     foreach (var i in g.Adj(v))
     {
         if (!marked[i])
         {
             DFS(g, i);
         }
     }
 }
Exemplo n.º 3
0
 private void DFS(Digraph 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);
 }