Introduction to Binary Search Trees
Implement insertion and search operations for a binary search tree.
Input format
The first line contains N. The second line contains N distinct integers.
Output format
Insert values in order into a BST. Print the preorder traversal.
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
5
50 30 70 20 40Expected output
50 30 20 40 70Example 2
Input
1
42Expected output
42