コード例 #1
0
        public static void MainMethod()
        {
            Console.WriteLine("Press x to exit");
            bool isContinue = true;

            {
                var selection = "4";// Console.ReadLine().Trim();
                isContinue = selection.ToLowerInvariant() != "x";
                if (!int.TryParse(selection, out int option))
                {
                    Console.WriteLine("Please try again ..");
                }

                switch (option)
                {
                case 1:
                    TreeRemove.Tests();
                    break;

                case 2:
                    MinHeapKClosestTests.Tests();
                    break;

                case 3:
                    WordCombinations.Tests();
                    break;

                case 4:
                    TreePaths.Tests();
                    break;
                }
            }

            Console.ReadLine();
        }
コード例 #2
0
        public static void Tests()
        {
            var tree = new TreeRemove();

            tree.Root = new Node(1)
            {
                Left = new Node(1)
                {
                    Left = new Node(0)
                    {
                        Left  = new Node(1),
                        Right = new Node(0)
                    }
                },
                Right = new Node(0)
                {
                    Left = new Node(1),
                }
            };

            tree.Print();
            tree.PerformTrim();
            tree.Print();


            var returnBottomLeft = new TreeRemove();

            returnBottomLeft.Root = new Node(1)
            {
                Left = new Node(2)
                {
                    Left = new Node(4)
                    {
                    }
                },
                Right = new Node(3)
                {
                }
            };

            var returnBottomLeft1 = new TreeRemove();

            returnBottomLeft1.Root = new Node(8)
            {
                Left = new Node(1)
                ,
                Right = new Node(4)
                {
                    Left = new Node(2)
                    {
                    }
                }
            };

            Console.WriteLine(returnBottomLeft1.ReturnBottomLeft());
            Console.WriteLine(returnBottomLeft.ReturnBottomLeft());
        }