文章
13
粉丝
168
获赞
13
访问
16.5k
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for(int i=s;i<e;i++)
#define per(i,s,e) for(int i=s;i>e;i--)
struct Tnode {
int data;
Tnode* lchild=NULL;
Tnode* rchild=NULL;
};
Tnode* insert(Tnode* root,Tnode* t){
if(root->data==t->data) return root;
else if(root->data > t->data){
if(root->lchild==NULL) {cout<<root->data<<endl; root->lchild=t;return root;}
else return insert(root->lchild,t);
}
else{
if(root->rchild==NULL) {cout<<root->data<<endl; root->rchild=t;return root;}
else return insert(root->rchild,t);
}
}
//1 6 5 9 8
Tnode* build_sorttree(Tnode* tree_root,vector<int> num){
Tnode* root = NULL;
rep(i,0,num.size()){
Tnode* t=new Tnode;
t->data=num[i];
if(i==0) {root=t;cout<<-1<<endl;}
else insert(root,t);
}
return root;
}
int main() {
int n,t; ve...
登录后发布评论
暂无评论,来抢沙发