文章
37
粉丝
1
获赞
294
访问
5.4k
只能过90%
#include<bits/stdc++.h>
using namespace std;
typedef struct node{
int data;
node* left;
node* right;
node* father;
}*BiTree;
BiTree build(BiTree root,int x,BiTree father){
if(root == nullptr){
BiTree t = new node;
t->left = nullptr;
t->right = nullptr;
t->data = x;
t->father = father;
return t;
}
if(root->data > x){
root->left = build(root->left,x,root);
}
else{
root->right = build(root->right,x,root);
}
return root;
}
void InOrder(BiTree root){
if(root == nullptr)
return ;
InOrder(root->left);
if(root->father == nullptr)
cout<<0<<' ';
else
cout<<root->father->data<<' ';
InOrder(root->right);
}
int main(){
int n;
cin>>n;
vector<int> v;
for(int i = 0 ; i < n; i++){
int t; cin>>t;
v.push_back(t);
}
BiTree root = nullptr;
for(int i = 0 ; i < v.size(); i++){
r...
登录后发布评论
暂无评论,来抢沙发