// Name: // Date: // JavaAB Period 9 // BSTreeMain.java // JavaAB Binary Search Tree Lab import java.io.*; import java.util.Scanner; public class BSTreeMain { public static void printMenu() { System.out.println("Make a choice from the menu below."); System.out.println("1. Print tree using in-order traversal"); System.out.println("2. Print tree using pre-order traversal"); System.out.println("3. Print tree using post-order traversal"); System.out.println("4. Count the number of nodes in the tree"); System.out.println("5. Count the number of leaves in the tree"); System.out.println("6. Find the height of the tree"); System.out.println("7. Find the longest path in the tree"); System.out.println("8. Find the largest valued node in the tree"); System.out.println("9. Find the smallest valued node in the tree"); System.out.println("10. Search for user-provided value"); System.out.println ("11. Delete user-provided value"); System.out.println("12. Quit"); System.out.println(); } public static void createTree(BSTree myTree, String expression) { // Get a characters from the String parameter. // Convert the character to String. // Value in a TreeNode must be an Object reference. // Build a tree after converting the character back to String // work with file data later for(int n = 0; n < expression.length(); n++) { char ch = expression.charAt(n); myTree.add((Character)ch); } } public static void main (String [] args) throws IOException { BSTree myTree = new BSTree(); BSTreeMain.printMenu(); BSTreeMain.createTree(myTree, "KECAJGHORSV"); Scanner scan = new Scanner(System.in); System.out.print ("Enter your choice: "); int choice = scan.nextInt(); switch(choice) { case 1: System.out.println("1. Print tree using in-order traversal"); System.out.println(myTree.inOrder()); break; case 2: System.out.println("2. Print tree using pre-order traversal"); System.out.println(myTree.preOrder()); break; case 3: System.out.println("3. Print tree using post-order traversal"); System.out.println(myTree.postOrder()); break; case 4: System.out.println("4. Count the number of nodes in the tree"); break; case 5: System.out.println("5. Count the number of leaves in the tree"); break; case 6: System.out.println("6. Find the height of the tree"); break; case 7: System.out.println("7. Find the longest path in the tree"); break; case 8: System.out.println("8. Find the largest valued node in the tree"); break; case 9: System.out.println("9. Find the smallest valued node in the tree"); break; case 10: System.out.println("10. Search for user-provided value"); break; case 11: System.out.println ("11. Delete user-provided value"); break; case 12: System.out.println("12. Quit"); break; } } }