예제 #1
0
        Stack <int> postReverseOrder; // this is used by the Topological Order call

        public DepthFirstOrder(Digraph g)
        {
            isMarked = new bool[g.V()];

            for (int i = 0; i < g.V(); i++)
            {
                if (!isMarked[i])
                {
                    DFS(g, i);
                }
            }
        }
예제 #2
0
        public DirectedCycle(Digraph dg)
        {
            marked  = new bool[dg.V()];
            onStack = new bool[dg.V()];
            edgeTo  = new int[dg.V()];

            for (int i = 0; i < dg.V(); i++)
            {
                if (!marked[i])
                {
                    DFS(dg, i);
                }
            }
        }
예제 #3
0
파일: SCC.cs 프로젝트: popomama/ALG2017
        public SCC(Digraph g)
        {
            dg = g;
            Digraph gReverse = g.Reverse();//get the reverse of the orinal graph

            isMarked = new bool[g.V()];

            //we will need do two passes of DFS

            //the first pass is to get the post reverse order of the reverse graph
            DepthFirstOrder dfs = new DepthFirstOrder(gReverse);
            //the reverse order will put the sink vertex of the orginal at the top of the stack returned
            IEnumerable <int> postReverse = dfs.PostReverseOrder();


            foreach (int v in postReverse)
            {
                if (!isMarked[v]) //now we remove one sink at a time, and find the SCC component
                {                 //the number of the SCC is equal to the number of the times we get isMarked[v]==true;
                    DFS(g, v);
                    count++;
                    Console.WriteLine(0);
                }
            }
        }