文章

43

粉丝

24

获赞

292

访问

6.5k

头像
二叉排序树 - 华科 题解:把父亲结点当做参数传进来就好了,easy
P1396 华中科技大学
发布于2025年3月7日 10:59
阅读数 101

#include <bits/stdc++.h>  
using namespace std;  
typedef struct node{
    int data;
    struct node *lchild,*rchild;
} *btree;
void ct(btree &T,int x,int father){//注意应使用引用! 
    if(T==NULL){
        T=new node;
        T->data=x;
        T->lchild=NULL;
        T->rchild=NULL;
        cout<<father<<endl;
        return;
    }
    if(x==T->data) return;
    else if(x<T->data) ct(T->lchild,x,T->data);
    else if(x>T->data) ct(T->rchild,x,T->data);
}

int main(){  
    int n;
    while(cin>>n) {
        btree T=NULL;
    &nb...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发