#include using namespace std; int n; struct node { int data; int id; struct node * left, *right; }; struct node *creat(struct node *root, int x) { if(!root) { struct node *t; t= new node; t->data = x; t->left = t->right = NULL; return t; } if(root->data < x) root->left = creat(root->left, x); else root->right = creat(root->right, x); return root; }; void bfs(struct node *root, int f) { queueq; root->id = 1; q.push(root); int flag = 0; while(!q.empty()) { if(flag) cout<<" "; struct node *now = q.front(); q.pop(); flag = 1; if(now->id > n) f = 1; cout<data; if(now->left) { now->left->id = now->id<<1; q.push(now->left); } if(now->right) { now->right->id = now->id<<1|1; q.push(now->right); } } cout<>n; for(int i = 0; i < n; i++) { cin>>x; root = creat(root,x); } bfs(root,f); return 0; }