Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve the next program while using the main method provide and make sure to get the EXACT output provide as well Write a method

Please solve the next program while using the main method provide and make sure to get the EXACT output provide as well

Write a method that does an inorder traverse of a 2-3-4 tree. It should display all the items in order, (add it to the folowing code). and use the main method provided

You MUST use this main method to solve the question:

public static void main(String[] args) throws IOException

{

long value;

Tree234 theTree = new Tree234();

theTree.insert(90);

theTree.insert(80);

theTree.insert(70);

theTree.insert(60);

theTree.insert(50);

theTree.insert(40);

theTree.insert(30);

theTree.insert(20);

theTree.insert(10);

theTree.insert(5);

theTree.insert(15);

theTree.insert(25);

theTree.insert(35);

theTree.insert(45);

theTree.insert(55);

theTree.insert(65);

theTree.insert(75);

theTree.insert(85);

theTree.insert(95);

theTree.insert(1);

theTree.insert(2);

theTree.insert(3);

theTree.insert(4);

theTree.insert(6);

theTree.insert(7);

theTree.insert(8);

theTree.insert(9);

while(true)

{

System.out.print("Enter first letter of ");

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

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 't':

theTree.traverse();

break;

default:

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

} // end switch

} // end while

} // end main()

You MUST get this output and please when you post the answer make sure to post the output that you get:

Enter first letter of show, insert, find or traverse: s

level=0 child=0 /20/

......level=1 child=0 /4/

............level=2 child=0 /2/

..................level=3 child=0 /1/

..................level=3 child=1 /3/

............level=2 child=1 /6/10/

..................level=3 child=0 /5/

..................level=3 child=1 /7/8/9/

..................level=3 child=2 /15/

......level=1 child=1 /60/

............level=2 child=0 /40/

..................level=3 child=0 /25/30/35/

..................level=3 child=1 /45/50/55/

............level=2 child=1 /80/

..................level=3 child=0 /65/70/75/

..................level=3 child=1 /85/90/95/

Enter first letter of show, insert, find or traverse: t

Traversal:

/1/2/3/4/5/6/7/8/9/10/15/20/25/30/35/40/45/50/55/60/65/70/75/80/85/90/95

Enter first letter of show, insert, find or traverse:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data And Hadoop Fundamentals Tools And Techniques For Data Driven Success

Authors: Mayank Bhushan

2nd Edition

9355516665, 978-9355516664

More Books

Students also viewed these Databases questions