Beispiel #1
0
        void Sort(TNode node)
        {
            node.Visited = true;
            foreach (var edge in _list.GetEdges(node))
            {
                if (!edge.Target.Visited)
                {
                    Sort(edge.Target);
                }
            }

            _results.Add(node);
        }
Beispiel #2
0
        void Compute(TNode v)
        {
            v.Index   = _index;
            v.LowLink = _index;
            _index++;

            _stack.Push(v);

            foreach (var edge in _list.GetEdges(v))
            {
                TNode n = edge.Target;
                if (n.Index == -1)
                {
                    Compute(n);
                    v.LowLink = Math.Min(v.LowLink, n.LowLink);
                }
                else if (_stack.Contains(n))
                {
                    v.LowLink = Math.Min(v.LowLink, n.Index);
                }
            }

            if (v.LowLink == v.Index)
            {
                TNode         n;
                IList <TNode> component = new List <TNode>();
                do
                {
                    n = _stack.Pop();
                    component.Add(n);
                }while (!v.Equals(n));

                if (component.Count != 1 || !v.Equals(component[0]))
                {
                    _result.Add(component);
                }
            }
        }