示例#1
0
 private void DFS(Digraph g, int v)
 {
     _onStack[v] = true;
     _marked[v]  = true;
     foreach (var w in g.Adjacent(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;
 }
示例#2
0
        public static int DegreeOut(Digraph g, int v)
        {
            int degree = 0;

            foreach (var w in g.Adjacent(v))
            {
                degree++;
            }
            return(degree);
        }
示例#3
0
 private void DFS(Digraph g, int v)
 {
     _marked[v] = true;
     foreach (var w in g.Adjacent(v))
     {
         if (!_marked[w])
         {
             DFS(g, w);
         }
     }
 }
示例#4
0
        private void DFS(Digraph g, int v)
        {
            _pre.Enqueue(v);

            _marked[v] = true;
            foreach (var w in g.Adjacent(v))
            {
                if (!_marked[w])
                {
                    DFS(g, w);
                }
            }

            _post.Enqueue(v);
            _reversePost.Push(v);
        }