当前位置:网站首页>二叉排序树的左旋与右旋
二叉排序树的左旋与右旋
2022-08-09 14:53:00 【黄小鸭233】
/*
|| ||
node left
// \ 对node右旋 / \\
left right ll node
/ \\ // \
ll lr lr right
*/
static void right_rotation(struct RBNode *node, RBTree *ptree)
{
struct RBNode *left = node->lchild;
left->parent = node->parent;
if(node->parent != NULL) //node结点不是根结点 存在父结点
{
if(node == node->parent->lchild) //node是左孩子 left也应该作为左孩子
node->parent->lchild = left;
else
node->parent->rchild = left;
}
else //node是根结点 旋转之后left作为根结点
{
*ptree = left;
}
node->lchild = left->rchild;
if(left->rchild != NULL)
left->rchild->parent = node;
left->rchild = node;
node->parent = left;
}
/*
|| |
node right
/ \\ 对node左旋 / \
left right node rr
// \ / \
rl rr left rl
*/
static void left_rotation(struct RBNode *node, RBTree *ptree)
{
struct RBNode *right = node->rchild;
right->parent = node->parent;
if(node->parent != NULL)
{
if(node == node->parent->lchild)
node->parent->lchild = right;
else
node->parent->rchild = right;
}
else
{
*ptree = right;
}
node->rchild = right->lchild;
if(right->lchild != NULL)
right->lchild->parent = node;
right->lchild = node;
node->parent = right;
}边栏推荐
- docker安装seata(指定配置文件、数据库、容器数据卷等)
- redis从入门到精通
- Matlab修改Consolas字体
- DSPE-PEG-Hydrazide, DSPE-PEG-HZ, Phospholipid-Polyethylene Glycol-Hydrazide MW: 1000
- 如何灵活运用量化交易接口的优势取长补短?
- DMPE-PEG-Mal Maleimide-PEG-DMPE dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide
- Servlet life cycle
- MongoDB adds permission management
- Talking about quantitative trading and programmatic trading
- EasyExcel的应用
猜你喜欢
随机推荐
Technology Sharing | How to Handle Header Cookies in Interface Automation Testing
[Basic version] Integer addition, subtraction, multiplication and division calculator
注解与反射
双摄像头系列原理深度剖析【转载】
In the process of quantitative trading, retail investors can do this
OpenSSF的开源软件风险评估工具:Scorecards
经典面试题 之 TCP 三次握手/ 四次挥手
量化投资者是如何获取实时行情数据的呢?
【超级账本开发者系列】专访——肖慧 : 不忘初心,方得始终
shell------常用小工具,sort,uniq,tr,cut
redis6在centos7的安装
OpenCV - 矩阵操作 Part 3
贝塞尔函数
相似图像的检测方法
运算符学习
OpenCV - Matrix Operations Part 3
6大论坛,30+技术干货议题,2022首届阿里巴巴开源开放周来了!
函数调用约定
Two-dimensional array to realize the eight queens problem
是什么推动了量化交易接口的发展?









