Esempio n. 1
0
        public void MinLevelTest()
        {
            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);
            }
            double result = 0.0;

            result = bst.MinLevel(bst.Root);

            Assert.AreEqual(bst.MinLevel(bst.Root), result);
        }
Esempio n. 2
0
        /// <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");
        }