static void Main(string[] args) { Console.WriteLine("Creating binary search tree ... !"); int[] input = new int[] { 9, 15, 5, 20, 16, 8, 12, 3, 6 }; Console.Write("Input Array - ({0})", string.Join(",", input)); var root = BinarySearchTreeHelper.InitializeBinarySearchTree(input); Console.WriteLine(); Console.WriteLine("Inorder traversal ... !"); InOrder(root); Console.WriteLine(); Console.WriteLine("Inserting new node with value 2"); BinarySearchTreeHelper.InsertIterative(root, 2); Console.WriteLine("Inorder traversal ... !"); InOrder(root); Console.WriteLine(); Console.WriteLine("Searching a node with value 16 using iteration"); Console.WriteLine("Found = {0}", SearchIterative(root, 16)); Console.WriteLine("Searching a node with value 16 using recursion"); Console.WriteLine("Found = {0}", SearchRecursive(root, 16)); Console.WriteLine("Searching a node with value 56 using iteration"); Console.WriteLine("Found = {0}", SearchIterative(root, 56)); Console.WriteLine("Searching a node with value 56 using recursion"); Console.WriteLine("Found = {0}", SearchRecursive(root, 56)); }
static void Main(string[] args) { Console.WriteLine("Creating binary search tree ... !"); int[] input = new int[] { 9, 15, 5, 20, 16, 8, 12, 3, 6 }; Console.Write("Input Array - ({0})", string.Join(",", input)); var root = BinarySearchTreeHelper.InitializeBinarySearchTree(input); Console.WriteLine(); Console.WriteLine("Inorder traversal ... !"); InOrder(root); int k1 = 5; int k2 = 12; Console.WriteLine(); Console.WriteLine("Printing b/w 5 and 12"); Print(root, k1, k2); }
static void Main(string[] args) { Console.WriteLine("Creating binary search tree ... !"); int[] input = new int[] { 9, 15, 5, 20, 16, 8, 12, 3, 6 }; Console.Write("Input Array - ({0})", string.Join(",", input)); var root = BinarySearchTreeHelper.InitializeBinarySearchTree(input); Console.WriteLine(); Console.WriteLine("Inorder traversal ... !"); InOrder(root); Console.WriteLine(); Console.WriteLine("Deleting node 8"); Delete(root, root, 8); Console.WriteLine("Inorder traversal ... !"); InOrder(root); Console.WriteLine(); Console.WriteLine("Deleting node 9"); Delete(root, root, 9); Console.WriteLine("Inorder traversal ... !"); InOrder(root); Console.WriteLine(); Console.WriteLine("ANOTHER VERSION"); Console.WriteLine("Creating binary search tree ... !"); int[] input1 = new int[] { 9, 15, 5, 20, 16, 8, 12, 3, 6 }; Console.Write("Input Array - ({0})", string.Join(",", input1)); var root1 = BinarySearchTreeHelper.InitializeBinarySearchTree(input1); Console.WriteLine(); Console.WriteLine("Inorder traversal ... !"); InOrder(root1); Console.WriteLine(); Console.WriteLine("Deleting node 8"); DeleteV2(root1, 8); Console.WriteLine("Inorder traversal ... !"); InOrder(root1); Console.WriteLine(); Console.WriteLine("Deleting node 9"); DeleteV2(root1, 9); Console.WriteLine("Inorder traversal ... !"); InOrder(root1); Console.WriteLine(); }
static void Main(string[] args) { Console.WriteLine("Creating binary search tree ... !"); int[] input = new int[] { 9, 15, 5, 20, 16, 8, 12, 3, 6 }; Console.Write("Input Array - ({0})", string.Join(",", input)); var root = BinarySearchTreeHelper.InitializeBinarySearchTree(input); Console.WriteLine(); /* * 9 * 5 15 * 3 8 12 20 * 6 16 * */ Console.WriteLine("Level Order Display"); LevelOrderDisplay(root); List <int> paths = new List <int>(); Console.WriteLine("Paths from root to leaf"); RootToLeaf(root, paths); }
static void Main(string[] args) { Console.WriteLine("Creating binary search tree ... !"); int[] input = new int[] { 9, 15, 5, 20, 16, 8, 12, 3, 6 }; Console.Write("Input Array - ({0})", string.Join(",", input)); var root = BinarySearchTreeHelper.InitializeBinarySearchTree(input); Console.WriteLine(); /* * 9 * 5 15 * 3 8 12 20 * 6 16 * */ Console.WriteLine("Level Order Display Before"); LevelOrderDisplay(root); Console.WriteLine("Level Order Display After"); var root1 = Mirror(root); LevelOrderDisplay(root1); }