1064 Complete Binary Search Tree (30 分)
#include <iostream>
#include <algorithm>
using namespace std;
int a[1050], tree[1050], n, ret;
void dfs(int root){
if(root > n)
return;
dfs(root * 2);
tree[root] = a[ret++];
dfs(root * 2 + 1);
}
int main() {
cin >> n;
for(int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a + n);
dfs(1);
for(int i = 1; i <= n; ++i)
cout << tree[i] << " \n"[i == n];
}