Binary Search Tree Inorder Walk and Free
hardQuestion 474Read an integer n, then n values, and insert each one into a binary search tree: a value smaller than a node goes left, larger goes right. If a value is already in the tree, ignore it — never store the same value twice.
Then print three lines: the inorder traversal, the value at the root, and the height of the tree. Height counts levels, so a tree that is just a root has height 1 and an empty tree has height 0.
For the input:
5 9 4 15 2 7
the program prints exactly the output shown in Expected Output.
Format: Inorder: followed by a space before every value with nothing after the last one, then Root: and the root's value, then Height: and the number of levels.
Free the memory you allocate before the program ends — this question checks for memory leaks.
Expected output
Inorder: 2 4 7 9 15 Root: 9 Height: 3
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...