Question: Use my code of 2 - 3 - 4 Trees I provided and modify it so that it works with 2 / 3 trees instead.
Use my code of Trees I provided and modify it so that it works with trees instead. It should support display, insertion and find methods.
Modify Division Operation:
Adjust the getNextChild method in the Tree class to compare data using division instead of subtraction.
Adjust Insertion Position:
Update the findItem method in the Node class to find the correct insertion position using division.
Split Nodes:
Modify the insert method in the Tree class to split nodes based on division.
Code Provided that needs to be modified
public class Tree
private Node root new Node;
public int findlong data
Node current root;
int currentNumber;
while true
if currentNumber current.findItemdata
return currentNumber;
else if currentisLeaf
return ;
else
current getNextChildcurrent data;
private Node getNextChildNode node, long data
int i;
int numItems node.getNumItems;
for i; i numItems; i
if data node.getItemidata
return node.getChildi;
return node.getChildi;
public void insertlong value
DataItem data new DataItemvalue;
Node current root;
while true
if currentisFull
splitcurrent;
current getNextChildcurrentgetParent value;
else if currentisLeaf
break;
else
current getNextChildcurrent value;
current.insertItemdata;
private void splitNode node
DataItem itemB, itemC;
Node child child parent;
int itemIndex;
itemC node.removeRightMostItem;
itemB node.removeRightMostItem;
child node.disconnectChild;
child node.disconnectChild;
if node root
parent new Node;
root parent;
root.connectChild node;
else
parent node.getParent;
itemIndex parent.insertItemitemB;
int n parent.getNumItems;
for int j n; j itemIndex; j
Node t parent.disconnectChildj;
parent.connectChildj t;
Node newRight new Node;
newRight.insertItemitemC;
newRight.connectChild child;
newRight.connectChild child;
parent.connectChilditemIndex newRight;
public void display
recursiveTraverseroot;
private void recursiveTraverseNode node
if node null
return;
node.displayNode;
for int i; i; i
recursiveTraversenodegetChildi;
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
