コード例 #1
0
        public int Height()
        {
            if (this.Root == null)
            {
                return(0);
            }
            var height = BST.Height(this.Root);

            Console.WriteLine($"Tree Height: {height}");
            return(height);
        }
コード例 #2
0
        public static void Demo()
        {
            BST tree = new BST();

            tree.AddNodes();

            while (true)
            {
                Console.Write("\n\t1.Print Infix, 2.Print Prefix, 3.Print Postfix\n\t4.Show Height\n\t5.Check Contains\n\t6.Find Min\n\t7.Find max\n\t8.InOrder Successor\n\t9.Delete a Node\n\t0:Exit\nEnter Choice: ");
                var input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    tree.PrintInFix();
                    break;

                case "2":
                    tree.PrintPreFix();
                    break;

                case "3":
                    tree.PrintPostFix();
                    break;

                case "4":
                    tree.Height();
                    break;

                case "5":
                    tree.Contains();
                    break;

                case "6":
                    tree.FindMin();
                    break;

                case "7":
                    tree.FindMax();
                    break;

                case "8":
                    tree.InOrderSuccessor();
                    break;

                case "9":
                    tree.DeleteNode();
                    break;

                case "0":
                    return;
                }
            }
        }