文章

25

粉丝

0

获赞

140

访问

4.3k

头像
二叉排序树 - 华科 题解:
P1396 华中科技大学
发布于2026年3月1日 15:46
阅读数 146

单独处理第一个根节点的父亲为-1,其余正常在建树过程输出

#include<bits/stdc++.h>
using namespace std;
typedef struct node{
    int data;
    struct node *lchild,*rchild;
}*BitTree;
//创建二叉排序树并且输出父亲
void BST(BitTree &T,int x){
    if(T == NULL){
        T = new node;
        T ->data = x;
        T ->lchild = NULL;
        T ->rchild = NULL;
        return;
    }
    if(T->data == x)
        return;
    else if(x < T->data){
        if(T->lchild == NULL)
            cout<<T->data<<endl;
        BST(T->lchild,x);
    }
    else{
   ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发