提交时间:2023-08-23 21:05:47
运行 ID: 99811
#include <iostream> using namespace std; struct tree{ int data; tree *left,*right; }gen; void insert(int const x,tree &jied){ if(x < jied.data){ if(jied.left.data == -1) jied.left.data = x; else insert(x,jied.left); } else{ if(jied.right.data == -1) jied.right.data = x; else insert(x,jied.right); } } void qingl(tree &x,int t){ if(t == 20) return; x.data = -1; qingl(x.left,t+1); qingl(x.right,t+1); } void bianl(tree jied){ if(jied.data == -1) return; cout << jied.data << ' '; bianl(jied.left); bianl(jied.right); } int main(){ int n,k; qingl(gen,0); cin >> n >> gen.data; while(--n){ cin >> k; insert(k,gen); } bianl(gen); return 0; }