描述
Given an array A1, A2, … AN, your task is to build a binary treee T which satisfies the following requirments:
T is a min-heap;
The inorder traversal sequence of T is A1, A2, … AN.
For example if the array is 3, 2, 8, 1, 4, 7, the tree is as below:
1
/ \
2 4
/ \ \
3 8 7
输入
The first line contain an integer N denoting the array length. (1 <= N <= 100)
The second line contains N distinct integers denoting A1, A2, … AN. (1 <= Ai <= 1000000)
输出
Output the preorder traversal sequence of T.
样例输入
6
3 2 8 1 4 7
样例输出
1 2 3 8 4 7
题意:
题目意思是有这样一个棵二叉树 T,满足 T 是小根堆,并且给出T的中序遍历的序列