相关疑难解决方法(0)

Tarjan循环检测帮助C#

这是tarjan循环检测的一个有效的C#实现.

该算法可在此处找到:http: //en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm

public class TarjanCycleDetect
    {
        private static List<List<Vertex>> StronglyConnectedComponents;
        private static Stack<Vertex> S;
        private static int index;
        private static DepGraph dg;
        public static List<List<Vertex>> DetectCycle(DepGraph g)
        {
            StronglyConnectedComponents = new List<List<Vertex>>();
            index = 0;
            S = new Stack<Vertex>();
            dg = g;
            foreach (Vertex v in g.vertices)
            {
                if (v.index < 0)
                {
                    strongconnect(v);
                }
            }
            return StronglyConnectedComponents;
        }

        private static void strongconnect(Vertex v)
        {
            v.index = index;
            v.lowlink = index;
            index++;
            S.Push(v);

            foreach (Vertex w in …
Run Code Online (Sandbox Code Playgroud)

c# algorithm directed-graph cycle tarjans-algorithm

31
推荐指数
3
解决办法
1万
查看次数

标签 统计

algorithm ×1

c# ×1

cycle ×1

directed-graph ×1

tarjans-algorithm ×1