This assignment requires you to write a non-verbose input-driven java program for maintaining a binary search tree (BST) of integer data elements (negative, zero or positive). The specialty of your BST will be that it will record the count for each integer element in it. The detailed requirements are as follows. When your program is executed, it should initialise an empty BST and a user should be presented with a menu1 of tasks that your program can perform on the BST. The menu options should be the following. 1. Insert an element into the BST 2. Search for an element in the BST 3. Find the maximum element from the BST 4. Find the minimum element from the BST 5. Print the elements in the BST in preorder 6. Print the elements in the BST in postorder 7. Print the elements in the BST in inorder 8. Delete an element 0. To exit the program Your program should not use command-line inputs. It should accept inputs from the user (stdin) at run-time. Your program should ask for the following two types of inputs. 1. An action from the menu denoted by one of the numbers 0, 1, . . . , 8 (as described in Section 1.1) 2. An integer element to be inserted to, searched for or deleted from the BST When the program asks for any kind of input from the user, it should be non-verbose2 . This means that no menu should be printed when the user is prompted for the input. In the second case, no description should be printed about the expected input. The user of the program will always know what input to provide when the program is expecting one. An element from the BST should always be printed (on stdout) along with its count. For example, if there is a node in the BST that contains the element −7, and its count is presently recorded as 2, the data in the node should be printed as −7(2) If the element (say 122) is not present in the BST, that should be reported as having the count 0. The output should look as follows. 122(0)
This assignment requires you to write a non-verbose input-driven java
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
Errors produced when calling 3. Find the maximum element from the BST or
4. Find the minimum element from the BST before adding elements so the program should output 0(0) instead of an error
"Exception in thread "main" java.lang.NullPointerException: Cannot read field "right" because "<local1>" is null
at BST.findMax(BST.java:109)
at BST.main(BST.java:194)"
"Exception in thread "main" java.lang.NullPointerException: Cannot read field "left" because "<local1>" is null
at BST.findMin(BST.java:118)
at BST.main(BST.java:197)"
Not compiling
javac BSTMain.java
BSTMain.java:151: error: cannot find symbol
BST bst = new BST();
^
symbol: class BST
location: class BSTMain
BSTMain.java:151: error: cannot find symbol
BST bst = new BST();
^
symbol: class BST
location: class BSTMain
2 errors
When I perform action 3 or 4 first I get an error "Exception in thread "main" java.lang.NullPointerException: Cannot read field "right" because "<local1>" is null
at BST.findMax(BST.java:109)
at BST.main(BST.java:194)"
How do you go about fixing this so, example input and output should be:
Command: echo 3 4 5 6 7 0 | java BST
Output: 0(0)0(0)