#include <stdio.h>
#include <stdlib.h>
typedef struct TTNode
{
int key;
int priority;
TTNode *p;
TTNode *left;
TTNode *right;
}TT,*pTT;
void leftRotate(pTT *root,pTT x)
{
if(x)
{
if(!x->right)
return;
pTT y=x->right;
y->p=x->p;
if(x->p==NULL)
*root=y;
else if(x==x->p->left)
x->p->left=y;
else
x->p->right=y;
x->right=y->left;
y->left=x;
x->p=y;
}
}
void rightRotate(pTT *root,pTT y)
{
if(y)
{
if(!y->left)
return;
pTT x=y->left;
x->p=y->p;
if(y->p==NULL)
*root=x;
else if(y==y->p->left)
y->p->left=x;
else
y->p->right=x;
y->left=x->right;
x->right=y;
y->p=x;
}
}
pTT newNode(int key,int priority)
{
pTT z=(pTT)malloc(sizeof(TT));
z->key=key;
z->left=NULL;
z->p=NULL
算法导论 思考题 13.3-4(Treap树)
最新推荐文章于 2021-06-27 15:15:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)