示例#1
0
        public void Run()
        {
            Digraph g        = BuildGraph(true);
            Cycle   cycle    = GetCycle(g);
            bool    hasCycle = cycle.HasCycle();

            if (hasCycle)
            {
                var    cycles   = cycle.GetCycle();
                string cycleStr = "";
                if (cycles != null)
                {
                    cycleStr = string.Join(",", cycles);
                }
                Console.WriteLine($"Has cycle, the cycle is : {cycleStr}");
            }
            else
            {
                Console.WriteLine("Hasn't cycle");
            }

            g        = BuildGraph(false);
            cycle    = GetCycle(g);
            hasCycle = cycle.HasCycle();
            if (hasCycle)
            {
                var    cycles   = cycle.GetCycle();
                string cycleStr = "";
                if (cycles != null)
                {
                    cycleStr = string.Join(",", cycles);
                }
                Console.WriteLine($"Has cycle, the cycle is : {cycleStr}");
            }
            else
            {
                Console.WriteLine("Hasn't cycle");
            }
        }
示例#2
0
 public override bool IsDag()
 {
     return(!_cycle.HasCycle());
 }