Question: In this assignment, you are to implement exercises 1 9 . 1 5 , and 1 9 . 1 6 on page 7 6 6
In this assignment, you are to implement exercises and on page of the book. You need to start with the BinaryNode.java and the BinarySearchTree.java files provided for you in the text. I recommend that you type them instead of obtaining them from the book's website. In order to test your code, you need to implement a driver program for this assignment. Your driver program must test all the methods that are provided in the BinarySearchTree class implementation repeatedly. So what you need to do is go into a while loop and a switch statement within it to handle all the choices. while quit was not selected switch choice case : Insert case : find case x: print the tree. default: quit. end switch end while One of the choices in your driver program must be to print the tree as shown in figure of the book except instead of using tabs as the character that signifies a level down the tree, use the character The tree should be available for printing at any point during the execution of the program. You need to submit all three files BinaryNode java, BinarySearchTree.java, and the driver You must not make any changes to the BinaryNode.java file, but submit it anyway. Good Luck protected BinaryNode findKth int k BinaryNode t if t null throw new IllegalArgumentException ; int leftSize t left null BinaryNodeWithSize t left size : ; if k leftSize return findkth k t left ; if k leftSize return t; return findkth k leftSize t right ; protected BinaryNode insert AnyType x BinaryNode tt BinaryNodeWithSize t BinaryNodeWithSize tt; if t null t new BinaryNodeWithSize x ; else if x compareTo t element t left insert x t left ; else if x compareTo t element t right insert x t right ; else throw new DuplicateItemException x toString ; t size ; return t; BinaryNodejava class BinaryNode BinaryNode AnyType theElement element theElement; left right null; AnyType element; BinaryNode left; BinaryNode right; BinarySearchTreejava public class BinarySearchTree public BinarySearchTree root null; public void insert AnyType x root insert x root ; public void remove AnyType x root remove x root ; public void removeMin root removeMin root ; public AnyType findMin return elementAt findMin root ; public AnyType findMax return elementAt findMax root ; public AnyType find AnyType x return elementAt find x root ; public void makeEmpty root null; public boolean isEmpty return root null; private AnyType elementAt BinaryNode t return t null null : t element; private BinaryNode find AnyType x BinaryNode t while t null if x compareTo t element t t left; else if x compareTo t element t t right; else return t; return null; protected BinaryNode findMin BinaryNode t if t null while t left null t t left; return t; private BinaryNode findMax BinaryNode t if t null while t right null t t right; return t; protected BinaryNode insert AnyType x BinaryNode t if t null t new BinaryNode x ; else if x compareTo t element t left insert x t left ; else if x compareTo t element t right insert x t right ; else throw new DuplicateItemException x toString ; return t; protected BinaryNode removeMin BinaryNode t if t null throw new ItemNotFoundException ; else if t left null t left removeMin t left ; return t; else return t right; protected BinaryNode remove AnyType x BinaryNode t if t null
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
