Question: Write the code in C++ Write a program called trees that does the following: It takes a single integer parameter: the number n of data

Write the code in C++

Write a program called trees that does the following:

  1. It takes a single integer parameter: the number n of data points in the tree.
  2. It reads n points from standard input. Each point has three integer components, which we call X, Y, and Z.
  3. As it reads those points, it places them in an initially empty binary tree T1 sorted on the X value. It resolves ties by going to the left.
  4. It traverses T1 in symmetric order, printing each point to standard output on a separate line in this format:
    (342, 512, 56311232) 
  5. It traverses T1 in preorder, placing each node in an initially empty binary tree T2 sorted on the Y value. It resolves ties by going to the left.
  6. It traverses T2 in postorder, printing each point on a separate line in the same format as before.
  7. It reads one more integer from standard input: the probe p, a Y value. It searches for p in T2, printing the last point it encounters as it descends through T2, which might have p itself as its Y value, or its Y value might just be close to p.

You must not use a library routine for trees; you must write your own routines.

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!