Question: in JAVA I am using Data Structure and algorithms 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 algorithms 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.

PLEASE USE 2-3 TREE

please use the following code below.

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("Insert D to display ");

System.out.print("display, insert, or find:");

char choice = getChar();

switch (choice)

{

case 'd':

theTree.displayTree();

break;

case 'i':

System.out.print("Insert value ");

value = getInt();

theTree.insert(value);

break;

case 'f':

System.out.print("Insert value to search for");

value = getInt();

int found = theTree.find(value);

if (found != -1)

{

System.out.println("Value Found " + value);

}

else

{

System.out.println("Could not find Value " + value);

}

break;

default:

System.out.print("Invalid entry ");

}

}

}

public static int getInt() throws IOException

{

String s = getString();

return Integer.parseInt(s);

}

public static char getChar() throws IOException

{

String s = getString();

return s.charAt(0);

}

public static String getString() throws IOException

{

InputStreamReader isr = new InputStreamReader(System.in);

BufferedReader br = new BufferedReader(isr);

String s = br.readLine();

return s;

}

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 Databases Questions!