Exemplo n.º 1
0
        private void StrongConnect(Vertex <T> v)
        {
            v.Index   = index;
            v.LowLink = index;
            index++;
            stack.Push(v);

            foreach (Vertex <T> w in v.Dependencies)
            {
                if (w.Index < 0)
                {
                    StrongConnect(w);
                    v.LowLink = System.Math.Min(v.LowLink, w.LowLink);
                }
                else if (stack.Contains(w))
                {
                    v.LowLink = System.Math.Min(v.LowLink, w.Index);
                }
            }

            if (v.LowLink == v.Index)
            {
                var        scc = new StronglyConnectedComponent <T>();
                Vertex <T> w;
                do
                {
                    w = stack.Pop();
                    scc.Add(w);
                } while (v != w);
                stronglyConnectedComponents.Add(scc);
            }
        }
            private void StrongConnect(Vertex <T> v)
            {
                v.Index   = _index;
                v.LowLink = _index;
                _index++;
                _stack.Push(v);

                foreach (var w1 in v.Dependencies)
                {
                    if (w1.Index < 0)
                    {
                        StrongConnect(w1);
                        v.LowLink = Math.Min(v.LowLink, w1.LowLink);
                    }
                    else if (_stack.Contains(w1))
                    {
                        v.LowLink = Math.Min(v.LowLink, w1.Index);
                    }
                }

                if (v.LowLink != v.Index)
                {
                    return;
                }

                var        scc = new StronglyConnectedComponent <T>();
                Vertex <T> w2;

                do
                {
                    w2 = _stack.Pop();
                    scc.Add(w2);
                } while (w2 != v);
                _stronglyConnectedComponents.Add(scc);
            }