程序填空题:Left-right Rotation
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
```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