文章
12
粉丝
0
获赞
12
访问
630
#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
int n;
int idx = 0;
typedef struct node{
int data;
node* lchild;
node* rchild;
}*BiTree;
BiTree build(int minv, int maxv){
if(idx >= n)
return NULL;
if(a[idx] < minv || a[idx] > maxv)
return NULL;
BiTree root = new node;
root->data = a[idx];
root->lchild = NULL;
root->rchild = NULL;
idx++;
root->lchild = build(minv,root->data);
root->rchild = build(root->data,maxv);
return root;
}
void LevelTravel(BiTree T){
queue<node*> q;
q.push(T);
while(!q.empty()){
node* t = q.front();
q.pop();
cout<<t->data<<' ';
if(t->lchild != NULL){
q.push(t->lchild);
}
if(t->rchild != NULL){
q.push(t->rchild);
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n;
for(int i = 0 ; i < n; i ++){
cin>>...
登录后发布评论
暂无评论,来抢沙发