/// <Main> /// Main function where everything is essentially run and called. /// </summary> /// <param name="args"></param> static void Main(string[] args) { List <string> myLst = new List <string>(); //List to hold input from user string usrList = String.Empty; BST myTree = new BST(); Console.WriteLine("Please enter a list of integers seperated by spaces [0,100]: \n"); //Get string from user usrList = Console.ReadLine(); Console.Write("\n"); myLst = usrList.Split(' ').ToList(); //Splits the string into a List of strings foreach (string temp in myLst.Distinct()) //Iterate through each string in the List<strings> **** Distinct will make sure the list is unique { int result = 0; if (int.TryParse(temp, out int value)) //Parse string into an integer { result = value; myTree.Root = myTree.Insert(myTree.Root, result); } } //Stats Console.WriteLine("\nTree Stats: \n"); Console.Write("inOrder Traversal: "); myTree.InOrderTraversal(myTree.Root); Console.WriteLine("\n Number of nodes: " + myTree.Count); Console.WriteLine(string.Format(" Height of tree: {0}", myTree.Levels(myTree.Root))); Console.WriteLine(string.Format(" Theoretical: Minimum levels for a tree with {0} nodes is {1}\n", myTree.Count, myTree.MinLevel(myTree.Root))); Console.WriteLine("\n"); Console.WriteLine("Program complete.\n"); }
public void LevelsTest() { BST bst = new BST(); List <int> myLst = new List <int> { 20, 30, 15, 1, 5, 55, 600, 43 }; foreach (int x in myLst) { bst.Root = bst.Insert(bst.Root, x); } Assert.AreEqual(4, bst.Levels(bst.Root)); }