Write a program that will generate a binary tree and then display the pre-order, in-order, and post-order traversal of the tree using a numerical sort order.
Program Requirements:
Hardcode the input in this exact order: 50, 75, 25, 15, 60, 35, 90, 42, 20, 27, 5, 55, 95, 80, 70.
Smaller values are added to the left, larger values are added to the right. Remember, in a binary tree, each node can have at most 2 offspring. Once you reach the maximum number of offspring, new nodes are added at the next level.
This website internet link icon. Three links of a chain in a gray box might help you visualize adding values to a binary tree. Type in one value at a time and press Insert.
Once the tree is created, calculate and display the order the vertices are visited in a pre-order, in-order, and post-order traversal through the tree.
For instance, creating this tree with these input values:
Input order: 5, 4, 9, 7, 6
would result in the following traversal order:
pre-order: 5, 4, 9, 7, 6
in-order: 4, 5, 6, 7, 9
post-order: 4, 6, 7, 9, 5
Additional Requirements: Do not hardcode the answers. The program must calculate them. If I were to change the numbers, the answers should change.