← Back to Pointers
Question 715
Binary Search Tree with Recursive Teardown
Binary Search Tree with Recursive Teardown
Build a binary search tree out of heap-allocated nodes, print it in order, then tear the whole thing down. Input (stdin): - Line 1: an integern, how many numbers follow (n is always at least 1) - Line 2:nintegers separated by spaces Insert each number into a binary search tree in which every node is created withnew. 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 input7then50 30 70 20 40 60 80the output is exactly what is shown in Expected Output. Line 1 is the literal textInorder:followed by every stored value in ascending order, each value preceded by a single space. Line 2 is the literal textCount:followed by how many nodes you actually created. Free the memory you allocate - this question checks for memory leaks. Write everything yourself, includingmain.
Expected Output:
Inorder: 20 30 40 50 60 70 80 Count: 7
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.