-->
当前位置:首页 > 题库 > 正文内容

程序填空题:Left-right Rotation

Luz4年前 (2021-05-10)题库1078
The function `LR_Rotation` is to do left-right rotation to the trouble-finder tree node `T` in an AVL tree.

```c++
typedef struct TNode *Tree;
struct TNode {
int key, h;
Tree left, right;
};

Tree LR_Rotation( Tree T )
{
Tree K1, K2;

K1 = T->left;
K2 = K1->right;
K1->right = @@[K2->left](2);
T->left = @@[K2->right](2);
K2->right = T;
@@[K2->left = K1](2);
/* Update the heights */
K1->h = maxh(Height(K1->left), Height(K1->right)) + 1;
T->h = maxh(Height(T->left), Height(T->right)) + 1;
K2->h = maxh(K1->h, T->h) + 1;

return K2;
}
```





答案:
第1空:K2->left

第2空:K2->right

第3空:K2->left = K1

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。