- 0
- 0
- 约3.92千字
- 约 18页
- 2019-09-27 发布于江苏
- 举报
/* Note:Your choice is C IDE *///平衡二叉树。
#include stdio.h
#include stdlib.h
typedef struct Node
{
int key;
struct Node*pLeft;
struct Node*pRight;
int bf;
}
Node;
void RightRotate(Node**pNode)// 右旋函数。
{
Node*pAxis=(*pNode)-pLeft;
(*pNode)-pLeft=pAxis-pRight;
pAxis-pRight=*pNode;
*pNode=pAxis;
}
void LeftRotate(Node**pNode)// 左旋函数。
{
Node*pAxis=(*pNode)-pRight;
(*pNode)-pRight=pAxis-pLeft;
pAxis-pLeft=*pNode;
*pNode=pAxis;
}
void LL_LR_Balance(Node**pNode)//LL型或LR函数。
{
Node*pLeft=(*pNode)-pLeft;
Node*pRight;
switch(pLeft-bf)
{
case 1:
(*pNode)-bf=pLeft-bf=0;
RightRota
原创力文档

文档评论(0)