Question: Please implement a 2 - 3 - 4 Tree in Java using the following framework: public class TwoFourTree { private class TwoFourTreeItem { int values

Please implement a 2-3-4 Tree in Java using the following framework:
public class TwoFourTree {
private class TwoFourTreeItem {
int values =1;
int value1=0; // always exists.
int value2=0; // exists iff the node is a 3-
node or 4-node.
int value3=0; // exists iff the node is a 4-
node.
boolean isLeaf = true;
TwoFourTreeItem parent = null; // parent exists iff the node
is not root.
TwoFourTreeItem leftChild = null; // left and right child exist
iff the note is a non-leaf.
TwoFourTreeItem rightChild = null;
TwoFourTreeItem centerChild = null; // center child exists iff the
node is a non-leaf 3-node.
TwoFourTreeItem centerLeftChild = null; // center-left and center-right
children exist iff the node is a non-leaf 4-node.
TwoFourTreeItem centerRightChild = null;
public boolean isTwoNode(){
return false;
}
public boolean isThreeNode(){
return false;
}
public boolean isFourNode(){
return false;
}
public boolean isRoot(){
return false;
}
public TwoFourTreeItem(int value1){
}
public TwoFourTreeItem(int value1, int value2){
}
public TwoFourTreeItem(int value1, int value2, int value3){
}
private void printIndents(int indent){
for(int i =0; i < indent; i++) System.out.printf("");
}
public void printInOrder(int indent){
if(!isLeaf) leftChild.printInOrder(indent +1);
printIndents(indent);
System.out.printf("%d
", value1);
if(isThreeNode()){
if(!isLeaf) centerChild.printInOrder(indent +1);
printIndents(indent);
System.out.printf("%d
", value2);
} else if(isFourNode()){
if(!isLeaf) centerLeftChild.printInOrder(indent +1);
printIndents(indent);
System.out.printf("%d
", value2);
if(!isLeaf) centerRightChild.printInOrder(indent +1);
printIndents(indent);
System.out.printf("%d
", value3);
}
if(!isLeaf) rightChild.printInOrder(indent +1);
}
}
TwoFourTreeItem root = null;
public boolean addValue(int value){
return false;
}
public boolean hasValue(int value){
return false;
}
public boolean deleteValue(int value){
return false;
}
public void printInOrder(){
if(root != null) root.printInOrder(0);
}
public TwoFourTree(){
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!