Question: public class BinarySearchTree > { private BinaryNode root; public BinarySearchTree ( ) { root = null; } public void insert ( AnyType x ) {
public class BinarySearchTree
private BinaryNode root;
public BinarySearchTree
root null;
public void insertAnyType x
root insertx root;
public void removeAnyType x
root removex root;
public AnyType findMin throws UnderflowException
if isEmpty
throw new UnderflowException;
return findMinrootelement;
public AnyType findMax throws UnderflowException
if isEmpty
throw new UnderflowException;
return findMaxrootelement;
public boolean containsAnyType x
return containsx root;
public void makeEmpty
root null;
public boolean isEmpty
return root null;
public void printTree
if isEmpty
System.out.printlnEmpty tree";
else
printTreeroot;
private BinaryNode insertAnyType x BinaryNode t
if t null
return new BinaryNodex null, null;
int compareResult xcompareTotelement;
if compareResult
tleft insertx tleft;
else if compareResult
tright insertx tright;
return t;
private BinaryNode removeAnyType x BinaryNode t
if t null
return t;
int compareResult xcompareTotelement;
if compareResult
tleft removex tleft;
else if compareResult
tright removex tright;
else if tleft null && tright null
telement findMintrightelement;
tright removetelement, tright;
else
t tleft null tleft : tright;
return t;
private BinaryNode findMinBinaryNode t
while t null && tleft null
t tleft;
return t;
private BinaryNode findMaxBinaryNode t
while t null && tright null
t tright;
return t;
private boolean containsAnyType x BinaryNode t
if t null
return false;
int compareResult xcompareTotelement;
if compareResult
return containsx tleft;
else if compareResult
return containsx tright;
else
return true;
private void printTreeBinaryNode t
if t null
printTreetleft;
System.out.printlntelement;
printTreetright;
private static class BinaryNode
AnyType element;
BinaryNode left;
BinaryNode right;
BinaryNodeAnyType theElement, BinaryNode lt BinaryNode rt
element theElement;
left lt;
right rt;
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
