예제 #1
0
 public Topological(Digraph g)
 {
     DirectedCycle cycleFinder = new DirectedCycle(g);
     if (!cycleFinder.HasCycle())
     {
         DepthFirstOrder dfs = new DepthFirstOrder(g);
         this.Order = dfs.ReversePost;
     }
 }
예제 #2
0
        public void TestDirectedCycle()
        {
            Digraph g = new Digraph(6);
            g.AddEdge(0, 5);
            g.AddEdge(5, 4);
            g.AddEdge(4, 3);
            g.AddEdge(3, 5);
            g.AddEdge(0, 1);
            g.AddEdge(1, 2);
            g.AddEdge(2, 3);
            Debug.WriteLine(g.ToString());

            DirectedCycle finder = new DirectedCycle(g);
            if (finder.HasCycle())
            {
                Debug.WriteLine("Directed cycle:");
                foreach (var v in finder.Cycle)
                    Debug.Write(" => " + v);
            }
            else
                Debug.WriteLine("No directed cycle!");
        }