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)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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)

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

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)"

Command:
Output:
Command:
Output:
e cho 8 100 3 4 5 6 7 1 100 1 200 1 300 1 400 8 100 5 7 0 | java Submission |
0 (0) 0 (0) 200 (1) 300 (1) 400 (1) 200 (1) 300 (1) 400 (1)
e cho 8 -80 3 4 1 -100 1 200 1 300 1 400 8 100 8 -100 5 6 0 | java Submission
0 (0)0 (0) 200 (1) 300 (1) 400 (1) 400 (1) 300 (1) 200 (1)
Transcribed Image Text:Command: Output: Command: Output: e cho 8 100 3 4 5 6 7 1 100 1 200 1 300 1 400 8 100 5 7 0 | java Submission | 0 (0) 0 (0) 200 (1) 300 (1) 400 (1) 200 (1) 300 (1) 400 (1) e cho 8 -80 3 4 1 -100 1 200 1 300 1 400 8 100 8 -100 5 6 0 | java Submission 0 (0)0 (0) 200 (1) 300 (1) 400 (1) 400 (1) 300 (1) 200 (1)
Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

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

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

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) 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education