Question
In JAVA I am using Data Structure and algoritms in Java Second Edition Program Must Compile and run! Modify the tree234.java program (Listing 10.1) so
In JAVA
I am using Data Structure and algoritms in Java Second Edition
Program Must Compile and run!
Modify the tree234.java program (Listing 10.1) so that it creates and works with 2-3 trees instead. It should display the tree and allow searches. It should also allow items to be inserted, but only if the parent of the leaf node (which is 516 CHAPTER 10 2-3-4 Trees and External Storage being split) does not also need to be split. This implies that the split() routine need not be recursive. In writing insert(), remember that no splits happen until the appropriate leaf has been located. Then the leaf will be split if its full. Youll need to be able to split the root too, but only when its a leaf. With this limited routine you can insert fewer than nine items before the program crashes.
Extend the program in Programming Project 10.4 so that the split() routine is recursive and can handle situations with a full parent of a full child. This will allow insertion of an unlimited number of items. Note that in the revised split() routine youll need to split the parent before you can decide where the items go and where to attach the children.
MUST COMPILE AND RUN ,PLEASE DISPLAY OUTPUT With Comments. IN TEXT
Main for (10.1) Below
This project can give you not more than 10 points.
public static void main(String[] args) throws IOException
{
long value;
Tree234 theTree = new Tree234();
theTree.insert(50);
theTree.insert(40);
theTree.insert(60);
theTree.insert(30);
theTree.insert(70);
while(true)
{
System.out.print("Enter first letter of ");
System.out.print("show, insert, find, or minimum: ");
char choice = getChar();
switch(choice)
{
case 's':
theTree.displayTree();
break;
case 'i':
System.out.print("Enter value to insert: ");
value = getInt();
theTree.insert(value);
break;
case 'f':
System.out.print("Enter value to find: ");
value = getInt();
int found = theTree.find(value);
if(found != -1)
System.out.println("Found "+value);
else
System.out.println("Could not find "+ value);
break;
case 'm':
value = theTree.getMin();
System.out.println("Minimum value is " + value);
break;
default:
System.out.print("Invalid entry ");
} // end switch
} // end while
} // end main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started