write a java program to read sequences of


Write a Java program to read sequences of integers from a text file, build a binary search tree for each sequence by inserting numbers in the sequence one after another into the search tree, and plot a picture of the finished tree. For example, if an input sequence contains 15, 3, 16, 2, 1, 4, 19, 17, and 28, the output for the sequence should look like:

2493_Write a Java program to read sequences.png

To make the project more manageable, we restrict the numbers to be in the range of [0, 99], and the height of any resultant binary search tree to be less than or equal to 4. This means that you can define a two-dimensional character array to represent the drawing area, with pre-determined root position and layout for a completely-filled binary tree of depth 4, To plot a search tree into the array, You start with root and fix offset to find the location for plotting the left and right subtree(if any) recuresively. Reduce the offset (e.g., divide it by 2) for each call that goes to a deeper level. At the end you can simply print the character array as a picture.

The numbers in each sequence are on the same line and are separated by a space. Two sequences are separated by an empty line. Your program should read a sequence and plot a search tree for the sequence, then read another sequence and plot a search tree for it, and keep doing so until the end of input. Specifically, the main method must look like:

BinaryTree T;

while (not end of input) {

build a binary search tree T;

plot T into the character array; //using recursion print the array;

}

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: write a java program to read sequences of
Reference No:- TGS0501380

Expected delivery within 24 Hours