From 822c70a81076543ae94b43fe5e42a244970771b9 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Sun, 8 Nov 2020 19:10:14 -0500 Subject: Move BinarySearchTest to esodata --- .../java/bjc/utils/examples/BinarySearchTest.java | 130 --------------------- 1 file changed, 130 deletions(-) delete mode 100644 base/src/examples/java/bjc/utils/examples/BinarySearchTest.java (limited to 'base') diff --git a/base/src/examples/java/bjc/utils/examples/BinarySearchTest.java b/base/src/examples/java/bjc/utils/examples/BinarySearchTest.java deleted file mode 100644 index 5e8e372..0000000 --- a/base/src/examples/java/bjc/utils/examples/BinarySearchTest.java +++ /dev/null @@ -1,130 +0,0 @@ -package bjc.utils.examples; - -import java.util.Scanner; - -import bjc.funcdata.bst.BinarySearchTree; -import bjc.funcdata.bst.TreeLinearizationMethod; - -/** - * Example showing how to use the binary search tree. - * - * @author ben - * - */ -public class BinarySearchTest { - private static void display(final BinarySearchTree tree, - final Scanner input) { - System.out.print( - "What order would you like the tree to be printed in (m for options): "); - char command; - - while (true) { - command = input.nextLine().charAt(0); - TreeLinearizationMethod method = null; - - switch (command) { - case 'm': - System.out.println("Possible tree printing methods: "); - System.out.println( - "\tp: Preorder printing (print parent first, then left & right)."); - System.out.println( - "\ti: Inorder printing (print left first, then parent & right)."); - System.out.println( - "\to: Postorder printing (print left first, then right & parent)."); - break; - case 'p': - method = TreeLinearizationMethod.PREORDER; - break; - case 'i': - method = TreeLinearizationMethod.INORDER; - break; - case 'o': - method = TreeLinearizationMethod.POSTORDER; - break; - default: - System.out.println("ERROR: Unknown command."); - } - - if (method != null) { - tree.traverse(method, element -> { - System.out.println("Node: " + element); - return true; - }); - - return; - } - - System.out.print( - "What order would you like the tree to be printed in (m for options): "); - } - } - - /** - * Main method of class - * - * @param args - * Unused CLI args - */ - public static void main(final String[] args) { - final Scanner input = new Scanner(System.in); - System.out.println("Binary Tree Constructor/Searcher"); - final BinarySearchTree tree - = new BinarySearchTree<>((o1, o2) -> o1 - o2); - - char command = ' '; - while (command != 'e') { - System.out.print("Enter a command (m for help): "); - command = input.nextLine().charAt(0); - - switch (command) { - case 'm': - System.out.println("Valid commands: "); - System.out.println("\tm: Display this help message."); - System.out.println("\te: Exit this program."); - System.out.println("\ta: Add a node to the binary tree."); - System.out.println("\td: Display the binary tree."); - System.out.println("\tr: Remove a node from the binary tree."); - System.out.println("\tf: Check if a given node is in the binary tree."); - System.out.println("\tt: Trim all deleted nodes from the tree."); - System.out.println("\tb: Balance the tree (also trims dead nodes)"); - break; - case 'a': - System.out.print("Enter the letter to add to the binary tree: "); - command = input.nextLine().charAt(0); - - tree.addNode(command); - break; - case 'r': - System.out.print("Enter the letter to add to the binary tree: "); - command = input.nextLine().charAt(0); - - tree.deleteNode(command); - break; - case 'd': - display(tree, input); - break; - case 'f': - System.out.print("Enter the letter to add to the binary tree: "); - command = input.nextLine().charAt(0); - - final boolean inTree = tree.isInTree(command); - if (inTree) { - System.out.printf("Node %s was found\n", command); - } else { - System.out.printf("Node %s was not found\n", command); - } - break; - case 't': - tree.trim(); - break; - case 'b': - tree.balance(); - break; - default: - System.out.println("ERROR: Unrecognized command."); - } - } - - input.close(); - } -} -- cgit v1.2.3