Ejemplo n.º 1
0
        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 (v != w2);

            _stronglyConnectedComponents.Add(scc);
        }
Ejemplo n.º 2
0
 public void Add(StronglyConnectedComponent <T> scc)
 {
     _collection.AddLast(scc);
 }