当前位置:网站首页>Implementation of balanced binary tree with C language
Implementation of balanced binary tree with C language
2022-06-22 20:01:00 【Just one word】
B Station turtle video
https://www.bilibili.com/video/BV1jW411K7yg?p=79
Blog Garden tutorial ( Step by step )
https://www.cnblogs.com/zhujunxxxxx/p/3348798.html
Small turtle code :
#define LH 1
#define EH 0
#define RH -1
typedef struct BiTNode
{
int data;
int bf;
struct BiTNode *lchild, *rchild;
} BiTNode, *BiTree;
void R_Rotate(BiTree *p)
{
BiTree L;
L = (*p)->lchild;
(*p)->lchild = L->rchild;
L->rchild = (*p);
*p = L;
}
void LeftBalance(BiTree *T)
{
BiTree L, Lr;
L = (*T)->lchild;
switch(L->bf)
{
case LH:
(*T)->bf = L->bf = EH;
R_Rotate(T);
break;
case RH:
Lr = L->rchild;
switch(Lr->bf)
{
case LH:
(*T)->bf = RH;
L->bf = EH;
break
case EH:
(*T)->bf = L->bf = EH;
break;
case RH:
(*T)->bf = EH;
L->bf = LH;
break;
}
Lr->bf = EH;
L_Rotate(&(*T)->lchild);
R_Rotate(T);
}
}
int InsertAVL(BiTree *T, int e, int *taller)
{
if( !*T )
{
*T = (BiTree)malloc(sizeof(BiTNode));
(*T)->data = e;
(*T)->lchild = (*T)->rchild = NULL;
(*T)->bf = EH;
*taller = TRUE;
}
else
{
if(e == (*T)->data)
{
*taller = FALSE;
return FALSE;
}
if(e < (*T)->data)
{
if(!InsertAVL(&(*T)->lchild, e, taller))
{
return FALSE;
}
if(*taller)
{
switch((*T)->bf)
{
case LH:
LeftBalance(T);
*taller = FALSE;
break;
case EH:
(*T)->bf = LH;
*taller = TRUE;
break;
case RH:
(*T)->bf = EH;
*taller = FALSE;
break;
}
}
}
else
{
if(!InsertAVL(&(*T)->rchild, e, taller))
{
return FALSE;
}
if(*taller)
{
switch((*T)->bf)
{
case LH:
(*T)->bf = EH;
*taller = FALSE;
break;
case EH:
(*T)->bf = RH;
*taller = TRUE;
break;
case RH:
RightBalance(T);
*taller = FALSE;
break;
}
}
}
}
}
边栏推荐
- [in depth understanding of tcapulusdb technology] tcapulusdb model
- 【小资说库】掰扯下概念:数据、数据库、数据库系统、数据库管理系统、数据库技术
- 【深入理解TcaplusDB技术】TcaplusDB机型
- 自己写了一个telnet命令
- 误用append案例一则
- 带超时的recv函数
- lua--数据类型、变量、循环、函数、运算符的使用
- 北京大学|通过对比学习实现离线元强化学习的鲁棒任务表示
- A text to show you the memory leak
- How to judge whether text is an array in the slot
猜你喜欢

数字经济加速落地,能为中小企业带来什么?

0816 shortcomings of Feida (improvement direction)

Yarn notes

推荐一个解剖学网站

使用 qrcodejs2 生成二维码详细API和参数

Solution de pin hors grille dans altium designer

0.1----- process of drawing PCB with AD

Some problem records of openpnp using process

详解openGauss多线程架构启动过程

Openpnp debugging ------ 0816 Feida Tui 0402 taping
随机推荐
修改隐含参数造成SQL性能下降案例之一
matplotlib设置坐标轴刻度间隔
Canvas picture frame
Definitions and terms of drawings
lua--迭代器、模块、元表
【深入理解TcaplusDB技术】TcaplusDB 表管理——重建表
Traversal of trees and forests
0816 shortcomings of Feida (improvement direction)
MySQL约束
University of Calgary | recommendation system based on Reinforcement Learning
北京大学|通过对比学习实现离线元强化学习的鲁棒任务表示
[compréhension approfondie de la technologie tcaplusdb] exploitation et entretien de tcaplusdb - inspection quotidienne des patrouilles
AB打包有的Shader没有触发IPreprocessShaders的回调
数字经济加速落地,能为中小企业带来什么?
51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭
3D打印机耗材受潮
How to judge whether text is an array in the slot
Array objects can be compared one by one (the original data with the same index and ID will be retained, and the data not in the original array will be added from the default list)
拓扑排序
区间检索SQL性能优化方法