1064 Complete Binary Search Tree (30 分)(******)

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 1001;
int n;
int indexn[maxn],cbt[maxn],ind = 0;

void inO(int root)
{
    if(root > n) return;
    inO(root * 2);
    cbt[root] = indexn[ind++];
    inO(root * 2 + 1);
}
int main()
{
    // freopen("1.txt","r",stdin);

    scanf("%d",&n);
    for(int i = 0;i<n;i++)
    {
        scanf("%d",&indexn[i]);
    }
    sort(indexn,indexn+n);
    inO(1);
    for(int i = 1;i<=n;i++)
    {
        printf("%d",cbt[i]);
        if(i!=n)
            printf(" ");
    }

    return 0;
}

发布了111 篇原创文章 · 获赞 4 · 访问量 3212

猜你喜欢

转载自blog.csdn.net/qq_15556537/article/details/100591440