10658 - Binary Search Tree   

Description

In this problem, you are to implement a binary search tree
with insert only operation

That is, insert a1,a2,...,ain order

Finally, output the preorder of the BST

Input

The first line is an integer T, the number of testcases.

For each testcase:
The first line is an integer n , the number of numbers to be inserted
The second line n positive integers a1,a2,...,an (numbers are distinct)

n, ai<=1000

Output

輸出一行以空白隔開BST的preorder 行末不要空白

Example:
for(i=0; i<100; i++){
    if(0<i)printf(" ");
    printf("%d",num[i]);
}
printf("\n");

Sample Input  Download

Sample Output  Download

Tags




Discuss