static void BinarySearchTreePrint() { var array = new int[] { 5, 3, 4, 7, 1, 9, 3, 8, 2 }; var bst = new BinarySearchTree <int>(Comparer <int> .Create((x, y) => x.CompareTo(y)), null, true); bst.Add(array); Console.WriteLine($"The depth is {bst.GetTreeDepth()}"); Console.WriteLine("Attempt to Find 9"); var found = bst.Find(7); if (found != null) { Console.WriteLine($"Found {found.Data}"); } Hr(); Console.WriteLine("Attempt to Remove 9"); bst.Remove(3); Hr(); Console.WriteLine("PreOrder Traversal"); bst.TraversePreOrder(); Hr(); Console.WriteLine("InOrder Traversal"); bst.TraverseInOrder(); Hr(); Console.WriteLine("PostOrder Traversal"); bst.TraversePostOrder(); Hr(); }
static void BinarySearchTreePrintString() { var array = new string[] { "dog", "cat", "bird", "rabbit", "frog", "fox", "cow", "squirrel", "mouse" }; var bst = new BinarySearchTree <string>(Comparer <string> .Create((x, y) => x.CompareTo(y)), null, true); bst.Add(array); Console.WriteLine($"The depth is {bst.GetTreeDepth()}"); Console.WriteLine("Attempt to Find 9"); Console.WriteLine(bst.Find("bird").Data); Hr(); Console.WriteLine("Attempt to Remove 9"); bst.Remove("fox"); Hr(); Console.WriteLine("PreOrder Traversal"); bst.TraversePreOrder(); Hr(); Console.WriteLine("InOrder Traversal"); bst.TraverseInOrder(); Hr(); Console.WriteLine("PostOrder Traversal"); bst.TraversePostOrder(); Hr(); }