Question: In JAVA I am using Data Structure and algoritms in Java Second Edition Program Must Compile and run! (10.1 This project should be easy. Write
In JAVA
I am using Data Structure and algoritms in Java Second Edition
Program Must Compile and run!
(10.1 This project should be easy. Write a program that returns the minimum value in a 2-3-4 tree.)
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.
MUST COMPILE AND RUN ,PLEASE DISPLAY OUTPUT With Comments. IN TEXT
Include Main method below in program
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
Get step-by-step solutions from verified subject matter experts
