Beispiel #1
0
        public static void Driver()
        {
            BinarySearchTree binarySearchTree = new BinarySearchTree();

            binarySearchTree.InsertRange(new int[] { 16, 8, 24, 4, 12, 20, 28, 2, 6, 10, 14, 18, 22, 26, 30, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25 });
            binarySearchTree.Insert(27);
            binarySearchTree.Insert(29);
            binarySearchTree.Insert(31);

            Console.WriteLine("In ordred traversing of Tree");
            binarySearchTree.InOrderTraversal(binarySearchTree.Root);
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Reverse Order traversing of Tree");
            binarySearchTree.ReverseOrderTraversal(binarySearchTree.Root);
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Pre Order traversing of Tree");
            binarySearchTree.PreOrderTraversal(binarySearchTree.Root);
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Post Order traversing of Tree");
            binarySearchTree.PostOrderTraversal(binarySearchTree.Root);
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("After deleting 4");
            binarySearchTree.Remove(binarySearchTree.Root, 4);
            binarySearchTree.InOrderTraversal(binarySearchTree.Root);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("After deleting 27");
            binarySearchTree.Remove(binarySearchTree.Root, 27);
            binarySearchTree.InOrderTraversal(binarySearchTree.Root);
            Console.WriteLine();


            Console.WriteLine();
            Console.WriteLine("Is is valid binary tree {0}", binarySearchTree.ValidBST());
        }