Question: code from A: public class BinarySearchTree { private TreeItem root; public BinarySearchTree ( ) { root = null; } public boolean insert ( String value
code from A:
public class BinarySearchTree
private TreeItem root;
public BinarySearchTree
root null;
public boolean insertString value
ifroot null
root new TreeItemvalue;
else
TreeItem parent null;
TreeItem current root;
whilecurrent null
ifvaluecompareTocurrentgetValue
return false;
else ifvaluecompareTocurrentgetValue
parent current;
current current.left;
else
parent current;
current current.right;
ifvaluecompareTocurrentgetValue
parent.left new TreeItemvalue;
else
parent.right new TreeItemvalue;
return true;
public boolean searchint value
TreeItem curr root;
whilecurr null
ifcurrgetValue value
return true;
else ifcurrgetValue value
curr curr.left;
else
curr curr.right;
return false;
private void inorderTreeItem root
ifrootnull
inorderrootleft;
System.out.print root;
inorderrootright;
public void inorder
inorderroot;
System.out.println ;
public class TreeItem
TreeItem left;
TreeItem right;
int value;
public TreeItemint value
left null;
right null;
this.value value;
public int getValue
return value;
public String toString
ifleft null && right null
return value have both children
;
else ifleft null
return value have left child
;
else ifright null
return value have right child
;
else
return value have no children
;
InputFile:
red
green
blue
yellow
orange
purple
indigo
pink
lime
white
black
brown
magenta
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
