当前位置:网站首页>二叉排序树的左旋与右旋
二叉排序树的左旋与右旋
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;
}边栏推荐
- xshell7连接工具下载
- VS2010:出现devenv.sln解决方案保存对话框
- 运算符学习
- Shell programming loop statement
- navicat for Oraclel链接oracle 报错oracle library is not loaded的解决办法
- What is a template engine?What are the common template engines?Introduction to common commands of thymeleaf.
- 百度开源e-chart初探
- For programming trading, focusing on forecast or on countermeasures?
- What is an index in MySql?What kinds of indexes are commonly used?When does an index fail?
- How do users correctly understand programmatic trading?
猜你喜欢

xshell7连接工具下载

Bean的生命周期

Regular Expressions for Shell Programming

常见编译问题

DBCO-PEG-DSPE, Phospholipid-Polyethylene Glycol-Dibenzocyclooctyne, Reaction Without Copper Ion Catalysis

DSPE-PEG-Hydrazide, DSPE-PEG-HZ, Phospholipid-Polyethylene Glycol-Hydrazide MW: 1000

走得通,看得见!你的交通“好帮手”

redis从入门到精通

Shell functions and arrays

shell之函数和数组
随机推荐
软件工程基础知识--软件过程模型
Qt控件-QTextEdit使用记录
在量化交易过程中,散户可以这样做
Mysql two engines comparison
DSPE-PEG-Hydrazide,DSPE-PEG-HZ,磷脂-聚乙二醇-酰肼MW:1000
Stock trading stylized how to understand their own trading system?
[Mysql]--Transaction, transaction isolation level, dirty read, non-repeatable read, phantom read analysis
对程序化交易系统接口有什么误区?
Mysql两个引擎对比
OpenSSF的开源软件风险评估工具:Scorecards
VS2010:出现devenv.sln解决方案保存对话框
Grad CAM 模型可视化
经典面试题 之 TCP 三次握手/ 四次挥手
EasyExcel的应用
是什么推动了量化交易接口的发展?
贝塞尔函数
redis从入门到精通
DMPE-PEG-Mal Maleimide-PEG-DMPE dimyristoylphosphatidylethanolamine-polyethylene glycol-maleimide
docker安装单机版redis、集群版redis
百度地图——鹰眼轨迹服务