We have to create a spellchecker for a class project. I've written code for a binary search tree, but need to update it for a tertiary search tree according to my prof. other then adding a third child, what should I do? Thanks for the help. Here's my code for the binary search tree.
public class BinaryTree {
static class Node {
int item;
Node Left,right;
}
Node root;
public BinaryTree() {}
private Node insertHelper(Node n, int item) {
if(n==null) {
Node temp = new Node();
temp.item = item;
return temp;
}
else if (item <= n.item) {
n.left = insertHelper(n.left, item);
return n;
}
else{
n.right = insertHelper(n.right, item);
return n;
}
}
public void insert(int item) {
this.root = insertHelper(this.root, item);
}
private boolean isPresentHelper(Node n, int item){
if (n == null) {
return false;
}
else if ( n.item==item) {
return true;
}
else if (item < n.item) {
return isPresentHelper(n.left,item);
}
else {
return isPresentHelper(n.right, item);
}
}
public boolean isPresent(int item){
return isPresentHelper(this.root, item);
}
private Node removeHelper(Node tree, int item){
if (tree == null){
return null;
}
else if(item < tree.item){
tree.left = removeHelper(tree.left, item);
return tree;
}
else if(item > tree.item){
tree.right = removeHelper(tree.right, item);
return tree;
}
else if (tree.left == null)
{
return tree.right;
}
else if (tree.right == null)
int {
return tree.left;
}
else{
int smallest_right = find Smallest(tree.right);
tree.item = smallest_right;
tree.right = removeHelper(tree.right,smallest_right);
return tree;
}
}
public void remove (int item) {
this.root = remove Helper(this.root, item);
}
private Node findSmallest(Node tree)
{
if(tree.left==null){
return
}
}