static void Main(string[] args) { Tree tree = new Tree(); int[] arr = { 5, 3, 7, 2, 4, 6, 8 }; //{ 1,2,3,4,5,6,7,8}; tree.CreateBinarySearchTree(arr); tree.Print(); Tree tree2=new Tree(); tree2.CreateBinarySearchTree(arr); Console.WriteLine("\nComparing 2 trees one cloned from the other. Are they equal?"); Console.WriteLine(Tree.IsEquivalentClone(tree.root, tree2.root) + "\n"); Tree mirrortree=new Tree(); mirrortree.root= tree.MakeMirrorCopyTree(); mirrortree.InorderPrintRecursive(mirrortree.root); Console.WriteLine("\nComparing 2 trees one cloned from the other. Are they mirror copies of each other?"); Console.WriteLine(Tree.IsMirrorCopy(tree.root, tree2.root)+"\n"); Console.WriteLine("\nComparing 2 trees one mirror copy of the other. Are they mirror copies of each other?"); Console.WriteLine(Tree.IsMirrorCopy(tree.root, mirrortree.root)+"\n"); Tree CompleteBinaryTree = new Tree(); CompleteBinaryTree.CreateBinaryTree(arr); CompleteBinaryTree.LevelOrderRecursiveTraversal(CompleteBinaryTree.root); //non recursive everything //find lca of two nodes //searching in tree //deleting nodes //convert to binary search tree Console.ReadLine(); }
static void Main(string[] args) { var tree = new Tree(); tree.Insert(7); tree.Insert(4); tree.Insert(9); tree.Insert(1); tree.Insert(6); tree.Insert(8); tree.Insert(10); var tree2 = new Tree(); tree2.Insert(7); tree2.Insert(4); tree2.Insert(9); tree2.Insert(1); tree2.Insert(6); tree2.Insert(8); tree2.Insert(10); //Console.WriteLine(tree.Find(7)); Console.WriteLine("Pre Order"); tree.TraversePreOrder(); Console.WriteLine(); Console.WriteLine("In Order"); tree.TraverseInOrder(); Console.WriteLine(); Console.WriteLine("Post Order"); tree.TraversePostOrder(); Console.WriteLine(); Console.WriteLine("The height of the tree is... " + tree.Height()); Console.WriteLine(); Console.WriteLine("The minimum value in the tree is... " + tree.Min()); Console.WriteLine(); Console.WriteLine(tree.Equals(tree2)); //tree.SwapRoot(); Console.WriteLine(tree.IsBinarySearchTree()); Console.WriteLine("Finding Nodes at a Distance..."); var nodes = tree.GetNodesAtDistance(2); foreach (var n in nodes) { Console.WriteLine(n); } Console.WriteLine("Traverse tree in level order..."); tree.TraverseLevelOrder(); Console.WriteLine(); Console.WriteLine("The size of the tree is... " + tree.Size()); Console.WriteLine(); Console.WriteLine("The number of leaves in the tree is... " + tree.CountLeaves()); Console.WriteLine(); Console.WriteLine("The maximum value in the tree is... " + tree.Max()); Console.WriteLine(); Console.WriteLine("Does the tree contain a certain value... " + tree.Contains(9)); Console.WriteLine(); Console.WriteLine("Are two values siblings... " + tree.AreSiblings(8, 10)); Console.WriteLine("Finding ancestors of a node..."); var ancestors = tree.GetAncestors(8); foreach (var n in ancestors) { Console.WriteLine(n); } Console.WriteLine(); Console.WriteLine("Checking for balance..."); Console.WriteLine("The tree is balanced: " + tree.IsBalanced()); Console.WriteLine(); Console.WriteLine("Checking for perfection..."); Console.WriteLine("The tree is perfect: " + tree.IsPerfect()); }