m0_72322824 2023-04-17 21:24 采纳率: 70.6%
浏览 23
已结题

平衡二叉树有什么问题吗?0xF报错是什么意思?

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

typedef int SBTType;

typedef struct SBBTree {
    SBTType data;
    struct SBBTree* lchild, * rchild;
    int hight;
}BTNode, *BTree;

int gethight(BTree root);
int whomax(int a, int b);
void LL(BTree* root);
void RR(BTree* root);
void avlInsert(BTNode** t,int x);

int gethight(BTree root ) {
    if (root) {
        return root->hight;
    }
    else {
        return 0;
    }
}


int whomax(int a, int b) {
    return a > b ? a : b;
}

void LL(BTree* root) {
    BTNode* mid= (*root)->lchild;
    (*root)->lchild = mid->rchild;
    mid->rchild = (*root);
    (*root) = mid;
    (*root)->hight = whomax(gethight((*root)->lchild), gethight((*root)->rchild)) + 1;
    mid->hight = whomax(gethight(mid->lchild), gethight(mid->rchild)) + 1;

}
void RR(BTree* root) {
    BTNode* mid = (*root)->rchild;
    (*root)->rchild = mid->lchild;
    mid->lchild = (*root);
    (*root) = mid;
    (*root)->hight = whomax(gethight((*root)->lchild), gethight((*root)->rchild)) + 1;
    mid->hight = whomax(gethight(mid->lchild), gethight(mid->rchild)) + 1;
}

void avlInsert(BTNode** t, int x) {
    if ((*t) == NULL) {
        (*t) = (BTNode*)malloc(sizeof(BTNode));
        if (!(*t)) {
            printf("fail");
        }
        else {
            (*t)->data = x;
            (*t)->lchild = NULL;
            (*t)->rchild = NULL;
            (*t)->hight = 0;
        }
    }
    else if ((*t)->data > x) {
        avlInsert(&((*t)->lchild), x);
        int Lh = gethight((*t)->lchild);
        int Rh = gethight((*t)->rchild);
        if (Lh - Rh == 2) {
            if (x < ((*t)->lchild)->data) {
                LL(t);
            }
            else {
                RR(&((*t)->lchild));
                LL(t);
            }
        }

    }
    else if ((*t)->data < x) {
        avlInsert(&((*t)->rchild), x);
        int Lh = gethight((*t)->lchild);
        int Rh = gethight((*t)->rchild);
        if (Lh - Rh == 2) {
            if (x > ((*t)->rchild)->data) {
                RR(t);
            }
            else {
                LL(&((*t)->rchild));
                RR(t);
            }
        }
    }
        (*t)->hight = whomax(gethight((*t)->lchild), gethight((*t)->rchild)) + 1;
    

}
void preOrder(BTNode* T) {
    if (T) {
        printf("%d ", T->data);
        preOrder(T->lchild);
        preOrder(T->rchild);
    }
}

int main ()
{
    BTree t;
    int num[5] = { 1,8,6,7,10 };
    for (int i = 0; i < 5; i++) {
        avlInsert(&t, num[i]);
    }
    preOrder(t);
    return 0;
}

img

  • 写回答

2条回答 默认 最新

  • 于扶摇 2023-04-18 11:16
    关注

    平衡二叉树是一种特殊的二叉树,它满足以下两个条件:

    左子树和右子树都是二叉搜索树,且左子树的所有节点的值都小于或等于右子树的所有节点的值。
    左子树和右子树的高度差不超过1。
    如果一个二叉树不满足这两个条件,那么它就不是一个平衡二叉树。

    0xF报错是一个编程错误,通常表示在编译过程中出现了未定义的行为或错误。具体来说,0xF是一个十六进制数,它可能代表一个特殊的二进制位或者一个无效的指令。如果在编译过程中出现了0xF错误,那么可能是因为程序中出现了与0xF相关的语法错误或逻辑错误,需要仔细检查代码并进行修改。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 5月1日
  • 已采纳回答 4月23日
  • 创建了问题 4月17日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效