コード例 #1
0
ファイル: Cycle.cs プロジェクト: allanma88/SampleCode
        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());
 }