Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use the main method in down to solve this problem. And please make sure don't give me any answer that already given..Thank you.. ////////////////////////////////////

Please use the main method in down to solve this problem. And please make sure don't give me any answer that already given..Thank you..

////////////////////////////////////

Again, start with the tree.java program and make a tree from characters typed by the user. This time, make a complete treeone that is completely full except possibly on the right end of the bottom row. The characters should be ordered from the top down and from left to right along each row, as if writing a letter on a pyramid. (This arrangement does not correspond to any of the three traversals we discussed in this chapter.) Thus, the string ABCDEFGHIJ would be arranged as One way to create this tree is from the top down, rather than the bottom up as in the previous two Programming Projects. Start by creating a node which will be the root of the final tree. If you think of the nodes as being numbered in the same order the letters are arranged, with 1 at the root, then any node numbered n has a left child numbered 2*n and a right child numbered 2*n+1. You might use a recursive routine that makes two children and then calls itself for each child. The nodes dont need to be created in the same order they are arranged on the tree. As in the previous Programming Projects, you can jettison the search-tree routines from the Tree class.

Please make sure to use this main method and output given here:

image text in transcribedimage text in transcribed

public static void main(String] args) throws IOException int value; System.out.print("Enter character string for tree: "); String str- getString); Tree theTree = new Tree(str); while(true) System.out.print("Enter first letter of "); System.out.print("show or traverse: "); int choice- getChar); switch(choice) case 's' the Tree displayTree); break; case t System.out.print("Enter type 1, 2 or 3: "); value = getInt(); the Tree.traverse(value); break; default: System.out.print("Invalid entry "); end switch ll end while end main() The output may look like: Enter character string for tree: ABCDEFGHID Enter first letter of show or traverse: s

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions