11372 - Create A Binary Search Tree   

Description

Please create a binary search tree, and support insert operation. Please ignore the repeat number and print out the tree with preorder sequence. (The root node is greater than the node in the left subtree and smaller than the node in the right subtree.)

Pre-order:

  1. Check if the current node is empty / null.
  2. Display the data part of the root (or current node).
  3. Traverse the left subtree by recursively calling the pre-order function.
  4. Traverse the right subtree by recursively calling the pre-order function

Input

The input contains two lines. The first line is a integer n (n<=8000) , and the second line is a sequence S, where S contain n non-negative integer number. (The first number in the sequence S is the root.) 

Output

Please print out the tree with preorder. (You don't need to write the print_tree(). You only need to create a binary search tree.)

Sample Input  Download

Sample Output  Download

Partial Judge Code

11372.c

Partial Judge Header

11372.h

Tags




Discuss