文章

38

粉丝

56

获赞

67

访问

4.1k

头像
二叉排序树 - 华科 题解:爆改高分篇例题
P1396 华中科技大学
发布于2025年3月4日 20:00
阅读数 95

//二叉排序树
#include <bits/stdc++.h>
using namespace std;

int m;

typedef struct node
{
    int data;
    struct node *lchild,*rchild;
}*BitTree;

void InsertBitTree(BitTree &T, int x) {
    if (T == NULL) {  // 当前子树为空,直接创建新节点
        T = new node;
        T->data = x;
        T->lchild = T->rchild = NULL;
        return;
    }

    if (x == T->data) return;  // 重复值不插入

    if (x < T->data) {
        if (T->lchild == NULL) {  // 左子树为空,直接创建并输出父节点值
            cout << T->data << endl;
            T->lchild = new node;
            T->lchild->data = x;
            T->lchild->lchild = T->lchild->rch...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发