Beispiel #1
0
 private void Dfs(IDiGraph g, int v)
 {
     onStack[v] = true;
     marked[v]  = true;
     foreach (int w in g.Adj(v))
     {
         if (HasCycle())
         {
             return;
         }
         else if (!marked[w])
         {
             edgeTo[w] = v;
             Dfs(g, w);
         }
         else if (onStack[w])
         {
             cycle = new Chapter1.Stack <int>();
             for (int x = v; x != w; x = edgeTo[x])
             {
                 cycle.Push(x);
             }
             cycle.Push(w);
             cycle.Push(v);
         }
         onStack[v] = false;
     }
 }
 private void Dfs(IDiGraph g, int s)
 {
     marked[s] = true;
     foreach (int w in g.Adj(s))
     {
         if (!marked[w])
         {
             Dfs(g, w);
         }
     }
 }
 private void Dfs(IDiGraph 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);
 }