Question: Write a C++ program(write code using code blocks) to read in as set of numbers and build an ordered binary tree. Your input file is

Write a C++ program(write code using code blocks) to read in as set of numbers and build an ordered binary tree. Your input file is TreeNbrsV2.txt. The file has integer numbers recorded in it and it also has duplicates numbers. You will read in a number, search the tree and if the input value is not found, insert a new node in the tree for the given value. If the input value is found, then you will count the value read in as a duplicate number, ie bump the counter. Each node will have a value field (the number read in) and a counter use to count the number of duplicates of said value. You are to input a single value then either insert or count the value after searching the tree. (You are not to do any other calculation below while reading and updating the binary tree.)

After building the tree, do the following tasks:

a. Print out the tree in inorder (the first 20 values)

b. Print out the tree in preorder. (the first 20 values)

c. Print out the tree in postorder. (the first 20 values)

d. Print out the number of nodes in the tree.

e. Sum up all the values in the tree (duplicates have to be counted duplicated times) and compute the average. Print the sum and the average.

f. Count the number of duplicates that was read in.

g. Count the number of leafs in the tree.

h. Print the number of nodes that have only one (1) child

i. Print the value that is the deepest leaf down in the tree.

j. Travers the tree and delete all nodes where the sum of the digits is less than 9

k. Print out the tree in inorder (the first 20 values)

l. Print out the number of nodes in the tree.

m. Sum up all the values in the tree (duplicates have to be counted duplicated times) and compute the average. Print the sum and the average.

Label all output.

Input file is on blackboard named TreeNbrsV2.txt

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!