From d2af58b0f68ebfbba2be7e7679efec6c8c0af12f Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 9 Feb 2017 11:50:31 -0500 Subject: Update --- .../java/bjc/utils/examples/BinarySearchTest.java | 44 +++++++++++----------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'BJC-Utils2/src/examples/java/bjc/utils') diff --git a/BJC-Utils2/src/examples/java/bjc/utils/examples/BinarySearchTest.java b/BJC-Utils2/src/examples/java/bjc/utils/examples/BinarySearchTest.java index c453e4b..1beaeec 100644 --- a/BJC-Utils2/src/examples/java/bjc/utils/examples/BinarySearchTest.java +++ b/BJC-Utils2/src/examples/java/bjc/utils/examples/BinarySearchTest.java @@ -12,17 +12,17 @@ import bjc.utils.funcdata.bst.TreeLinearizationMethod; * */ public class BinarySearchTest { - private static void displayTree(BinarySearchTree tree, - Scanner inputSource) { + private static void display(BinarySearchTree tree, + Scanner input) { System.out.print( "What order would you like the tree to be printed in (m for options): "); char command; while (true) { - command = inputSource.nextLine().charAt(0); + command = input.nextLine().charAt(0); - TreeLinearizationMethod linearizationMethod = null; + TreeLinearizationMethod method = null; switch (command) { case 'm': @@ -36,23 +36,23 @@ public class BinarySearchTest { break; case 'p': - linearizationMethod = TreeLinearizationMethod.PREORDER; + method = TreeLinearizationMethod.PREORDER; break; case 'i': - linearizationMethod = TreeLinearizationMethod.INORDER; + method = TreeLinearizationMethod.INORDER; break; case 'o': - linearizationMethod = TreeLinearizationMethod.POSTORDER; + method = TreeLinearizationMethod.POSTORDER; break; default: System.out.println("ERROR: Unknown command."); } - if (linearizationMethod != null) { - tree.traverse(linearizationMethod, (element) -> { + if (method != null) { + tree.traverse(method, (element) -> { System.out.println("Node: " + element); return true; }); @@ -72,18 +72,18 @@ public class BinarySearchTest { * Unused CLI args */ public static void main(String[] args) { - Scanner inputSource = new Scanner(System.in); + Scanner input = new Scanner(System.in); System.out.println("Binary Tree Constructor/Searcher"); char command = ' '; - BinarySearchTree searchTree = new BinarySearchTree<>( + BinarySearchTree tree = new BinarySearchTree<>( (o1, o2) -> o1 - o2); while (command != 'e') { System.out.print("Enter a command (m for help): "); - command = inputSource.nextLine().charAt(0); + command = input.nextLine().charAt(0); switch (command) { case 'm': @@ -106,39 +106,39 @@ public class BinarySearchTest { case 'a': System.out.print( "Enter the letter to add to the binary tree: "); - command = inputSource.nextLine().charAt(0); + command = input.nextLine().charAt(0); - searchTree.addNode(command); + tree.addNode(command); break; case 'r': System.out.print( "Enter the letter to add to the binary tree: "); - command = inputSource.nextLine().charAt(0); + command = input.nextLine().charAt(0); - searchTree.deleteNode(command); + tree.deleteNode(command); break; case 'd': - displayTree(searchTree, inputSource); + display(tree, input); break; case 'f': System.out.print( "Enter the letter to add to the binary tree: "); - command = inputSource.nextLine().charAt(0); + command = input.nextLine().charAt(0); System.out.println("Node " + command + " was " - + (searchTree.isInTree(command) ? "" : "not ") + + (tree.isInTree(command) ? "" : "not ") + "found"); break; case 't': - searchTree.trim(); + tree.trim(); break; case 'b': - searchTree.balance(); + tree.balance(); break; default: @@ -146,6 +146,6 @@ public class BinarySearchTest { } } - inputSource.close(); + input.close(); } } -- cgit v1.2.3