文章
74
粉丝
0
获赞
98
访问
9.0k
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
int data;
struct node *lchild, *rchild;
}*BitTree;
void Insert(BitTree &T, int x){
if(T == NULL){
T = new node;
T->data = x;
T->lchild = NULL;
T->rchild = NULL;
return;
}
if(x < T->data){
if(T->lchild == NULL) cout << T->data << endl;
Insert(T->lchild, x);
}
else if(x > T->data){
if(T->rchild == NULL) cout << T->data << endl;
Insert(T->rchild, x);
}
}
int main(){
int n;
while(cin >> n){
BitTree root = NULL;
cout << "-1" << endl;
for(int i = 0; i < n; i++){
int x; cin >> x;
Insert(root, x);
}
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发