Write a java program to read sequences of integers

Assignment Help JAVA Programming
Reference no: EM13188767

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;

}

Reference no: EM13188767

Questions Cloud

Derive an equation for p0 as a function : A loan of P0 which accrues an interest i per period is to be paid of with a uniform gradient annuity with initial payment A and gradient G over n periods. Thus, the change in the amount of principal is governed by Pn =Pn-1(1+i)-A0 -(n-1) G (1)
How fast is the water level rising : A trough is 20 ft long and its ends have the shape of isosceles triangles that are 1.5 ft across at the top and have a height of 1 ft. If the trough is being filled with water at a rate of 11 ft3/min, how fast is the water level rising when the wa..
Which job should he have accepted : one in Toronto, Ontario, and the other in Halifax, Nova Scotia. Assume that both jobs were equally interesting to Sam and that he was indifferent between relocating to Toronto or staying in Halifax. Both positions offered a salary of $52,000.
Find the dimensions of the new corral : an existing rectangular corral such that the total area of the new corral is 1.5 times that of the original corral. the current corral's dimensions are 250 feet by 160 feet. The rancher wants to increase each dimension by the same amount.
Write a java program to read sequences of integers : 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.
What is the means number of on time flights per 15 flights : if an air flight arrives on time .60% of the time and 15 flights are observed, what is the means number of on time flights per 15 flights.
Are there any qualitative factors that should be considered : Management is often faced with the alternative of continuing to make a product or component internally, or going to an external source and purchasing the product or component. In gathering relevant information for these two alternatives, briefly i..
Find two positive numbers satisfying the given requirements : Find two positive numbers satisfying the given requirements: the sum is 120 and the product is a maximum.
Write a compound inequality to show the acceptable speed : The cruise-control function on Georgina's car should keep the speed of the car within 3mi/h of the set speed. Write a compound inequality to show the acceptable speed s if the set speed is 55 il/h. graph the solutions.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a program that will calculate monthly pay

Write a program that will calculate monthly pay and expenses for a commercial utility sales person. Sales employees in this company are paid monthly. Each employee is paid a base pay of $1,000 and 9½ % commission on sales. The company deducts 18% of..

  Write a generic class

Write a generic class (using Java generics) called Pair that stores two values of the generic type.  It should have a constructor to set them, two methods getfirst() and getsecond() to retrieve them.

  Technical community blog

Write a blog article for a coding and technical community blog.

  Java application to display multiple choice questions

Write down the application which displays series of TEN(10) multiple choice questions: questions must cover all the Java. Each question must have four possible answers and only one answer must be correct.

  Write java program which simulates flipping of coin

Write a Java program which simulates flipping of coin 1000 times and prints total number of heads and tails. You should create a class.

  Tic-tac-toe game assignment

Assignment 1(Java): Tic-Tac-Toe Game (Assignment 1 is attached),  Use the concepts and scenario from Assignment 1 and continue with the tic-tac-toe game design and development.  Section 1: Java Program File, The following method, numPaths, is suppos..

  One search function

One search function will use a sentinel to mark the end of the array. The other search function will use an array length (maximum legal index into the array) to determine when to exit the search loop. Both functions must return true when the searc..

  To translate infix mathematical expression

Write a program in java to translate infix mathematical expression into postfix expression and a program to evaluate the postfix expression

  Statements to print a label

Add the statements to print a label in the following format (the numbers in the example output are correct for input of $4.25 per pound and 41 ounces). Use the formatting object money to print the unit price and total price and the formatting object ..

  Dijikstra for undirected graph using simple scheme

Dijikstra for undirected graph using simple scheme with array and fibonacci heap and compare the performance/results, preferably in java.

  A program that reads in two integers typed on the keyboard

Write a program that reads in two integers typed on the keyboard and outputs their sum, difference, and product. Must compile correctly in Eclipse. Here is what I have done, but its wrong.

  Design a java program that has two parallel arrays

Design a java program that has two parallel arrays: a string array named people that is initialized with the names of seven of your friends, and a string array named phoneNumbers that is initialized with your friends phone numbers.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd