Binary Search Tree with Recursive Teardown
hardQuestion 715Build a binary search tree out of heap-allocated nodes, print it in order, then tear the whole thing down.
Input (stdin):
- Line 1: an integer n, how many numbers follow (n is always at least 1)
- Line 2: n integers separated by spaces
Insert each number into a binary search tree in which every node is created with new. Smaller values go left, larger values go right, and a value that is already in the tree is IGNORED (no duplicate node is created).
Then print exactly two lines. For the input 7 then 50 30 70 20 40 60 80 the output is exactly what is shown in Expected Output.
Line 1 is the literal text Inorder: followed by every stored value in ascending order, each value preceded by a single space. Line 2 is the literal text Count: followed by how many nodes you actually created.
Free the memory you allocate - this question checks for memory leaks.
Write everything yourself, including main.
Expected output
Inorder: 20 30 40 50 60 70 80 Count: 7
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...