文章
12
粉丝
0
获赞
8
访问
325
#include <bits/stdc++.h>
using namespace std;
struct node{
int val;
node* left;
node* right;
};
void Insert(node* &root,int t,int father){
if (root==nullptr){
root=new node{t,nullptr,nullptr};
cout<<father<<endl;
}
else if(t>=root->val){
Insert(root->right,t,root->val);
}
else if(t<root->val){
Insert(root->left,t,root->val);
}
}
int main(){
int N;
cin>>N;
node* tree=nullptr;
for(int i=0;i<N;i++){
int t;
cin>>t;
Insert(tree,t,-1);
}
}
登录后发布评论
暂无评论,来抢沙发