Esempio n. 1
0
 private void dfs(DiGraph G, int v)
 {
     marked[v] = true;
     foreach (int w in G.Adj(v))
         if (!marked[w])
             dfs(G, w);
 }
Esempio n. 2
0
 private void dfs(DiGraph G, int v)
 {
     onStack[v] = true;
     marked[v]  = true;
     foreach (int w in G.Adj(v))
     {
         if (this.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;
 }
Esempio n. 3
0
 private void dfs(DiGraph G, int v)
 {
     pre.Enqueue(v);
     marked[v] = true;
     foreach (int w in G.Adj(v))
         if (!marked[w])
             dfs(G, w);
     post.Enqueue(v);
     reversePost.Push(v);
 }
Esempio n. 4
0
 private void dfs(DiGraph G, int v)
 {
     marked[v] = true;
     foreach (int w in G.Adj(v))
     {
         if (!marked[w])
         {
             dfs(G, w);
         }
     }
 }
Esempio n. 5
0
 private void dfs(DiGraph G, int v)
 {
     pre.Enqueue(v);
     marked[v] = true;
     foreach (int w in G.Adj(v))
     {
         if (!marked[w])
         {
             dfs(G, w);
         }
     }
     post.Enqueue(v);
     reversePost.Push(v);
 }
Esempio n. 6
0
 private void dfs(DiGraph G, int v)
 {
     onStack[v] = true;
     marked[v] = true;
     foreach (int w in G.Adj(v))
         if (this.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;
 }