Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //New students from the students class are created.
            BST.Student Charles  = new BST.Student("Charles", "Economics", "IL");
            BST.Student Mike     = new BST.Student("Mike", "Computer Science", "WA");
            BST.Student Alice    = new BST.Student("Alice", "Math", "WA");
            BST.Student Jennifer = new BST.Student("Jennifer", "Health and Science", "WA");

            //Instantiate the tree and insert the student nodes.
            BST myTree = new BST();                             //              Charles

            myTree.insert(Charles);                             //              /     \
            myTree.insert(Mike);                                //           Alice    Mike
            myTree.insert(Alice);                               //              \
            myTree.insert(Jennifer);                            //           Jennifer
            myTree.insert("Carl", "Liberal Arts", "HI");        //             /
                                                                //           Carl
                                                                //Search for students(output is boolean value).
            Console.WriteLine(myTree.search("Carl"));
            Console.WriteLine(myTree.search("Carlos"));

            //Traverse the tree.
            myTree.printInOrder();   //LNR
            Console.WriteLine(" ");
            myTree.printPreOrder();  //NLR
            Console.WriteLine(" ");
            myTree.printPostOrder(); //LRN
            Console.WriteLine(" ");

            //Output the Height and Number of Leaves on the the tree.
            Console.WriteLine(myTree.printHeight());       //Output: 4
            Console.WriteLine(" ");
            Console.WriteLine(myTree.printNumLeafNodes()); //Output 2
        }