Example #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;
 }
Example #2
0
 private void Dfs(Digraph G, int v)
 {
     _marked[v] = true;
     foreach (var w in G.Adj(v))
     {
         if (!_marked[w])
         {
             Dfs(G, w);
         }
     }
 }
Example #3
0
 private void Dfs(Digraph G, int v)
 {
     _pre.Enqueue(v);
     _marked[v] = true;
     foreach (var w in G.Adj(v))
     {
         if (!_marked[w])
         {
             Dfs(G, w);
         }
     }
     _reversePost.Push(v);
     _post.Enqueue(v);
 }