当前位置:网站首页>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;
}
}
}
}
}
边栏推荐
- libcef最新下载地址-在VS2015下编译为MD-动态链接
- 0.0 - Solidworks如何才能卸载干净?
- Yarn notes
- C WinForm embedded flash
- Nlp-d57-nlp competition D26 & skimming questions D13 & reading papers & finding bugs for more than an hour
- Comparison of NAND flash particles SLC, MLC, TLC and QLC
- 数字货币钱包开发不知道怎么选?
- 【深入理解TcaplusDB技术】运维平台中实现TcaplusDB事务管理
- 安装Office的一些工具
- [petty bourgeoisie database] break down the concept: data, database, database system, database management system, database technology
猜你喜欢

Traversal of trees and forests

Chapter I 100 hot questions (1-5)

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

Some problem records of openpnp using process

51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭

51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭

Follow up course supplement of little turtle teacher "take you to learn C and take you to fly"

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

小甲鱼老师《带你学C带你飞》的后续课程补充

1.2----- mechanical design tools (CAD software) and hardware design tools (EDA software) and comparison
随机推荐
lua--迭代器、模块、元表
数字经济加速落地,能为中小企业带来什么?
[petty bourgeoisie database] break down the concept: data, database, database system, database management system, database technology
树和森林的遍历
【深入理解TcaplusDB技术】TcaplusDB运维单据
【深入理解TcaplusDB技术】TcaplusDB事务管理——错误排查
再谈SQL profile : 到底能不能固定执行计划?
【深入理解TcaplusDB技术】TcaplusDB 表管理——新建表
自定义控件AutoScaleMode为Font造成宽度增加的问题
0.0 - how can SolidWorks be uninstalled cleanly?
第一篇 热身--隐式类型转换还是其他?
matlab调用API
0.1-----用AD画PCB的流程
【深入理解TcaplusDB技术】入门Tcaplus-JDBC开发
卡尔加里大学|基于强化学习的推荐系统综述
漫话Redis源码之一百一十九
[deeply understand tcapulusdb technology] tcapulusdb transaction management - error troubleshooting
拓扑排序
MySQL多表操作
二叉排序树的查找、插入和删除