二叉排序树:
http://www.patest.cn/contests/pat-a-practise/1064
1 #include <iostream> 2 #include <vector> 3 #include<algorithm> 4 using namespace std; 5 6 int ans[1002]; 7 8 int cnt = 0; 9 10 void inoder(vector<int> vv,int x,int n) 11 { 12 if(2*x <= n) 13 { 14 inoder(vv,2*x,n); 15 } 16 ans[x] = vv[cnt++]; 17 if(2*x + 1 <= n) 18 { 19 inoder(vv,2*x +1,n); 20 } 21 } 22 23 24 int main() 25 { 26 int n,tem; 27 vector<int> vv; 28 cin >> n; 29 int i = n; 30 while(i--) 31 { 32 cin >> tem; 33 vv.push_back(tem); 34 } 35 sort(vv.begin(),vv.end()); 36 inoder(vv,1,n); 37 bool fir = 1; 38 for(i = 1 ; i <= n ;++i) 39 { 40 if(fir) 41 { 42 fir = 0; 43 cout << ans[i]; 44 } 45 else 46 { 47 cout << " " << ans[i]; 48 } 49 } 50 cout << endl; 51 return 0; 52 }