中序遍历建树
#include<bits/stdc++.h> using namespace std; const int N=1e3+10; int s[N]; int n; int tree[N]; int cnt; void inorder(int root) { if(root>n) return; inorder(root*2); tree[root]=s[cnt++]; inorder(root*2+1); } int main() { scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&s[i]); sort(s,s+n); inorder(1); for(int i=1;i<=n;i++){ if(i!=1) printf(" "); printf("%d",tree[i]); } return 0; }