📄 rotations.java
字号:
package DataStructures;
final class Rotations
{
/**
* Rotate binary tree node with left child.
* For AVL trees, this is a single rotation for case 1.
*/
static BinaryNode withLeftChild( BinaryNode k2 )
{
BinaryNode k1 = k2.left;
k2.left = k1.right;
k1.right = k2;
return k1;
}
/**
* Rotate binary tree node with right child.
* For AVL trees, this is a single rotation for case 4.
*/
static BinaryNode withRightChild( BinaryNode k1 )
{
BinaryNode k2 = k1.right;
k1.right = k2.left;
k2.left = k1;
return k2;
}
/**
* Double rotate binary tree node: first left child
* with its right child; then node k3 with new left child.
* For AVL trees, this is a double rotation for case 2.
*/
static BinaryNode doubleWithLeftChild( BinaryNode k3 )
{
k3.left = withRightChild( k3.left );
return withLeftChild( k3 );
}
/**
* Double rotate binary tree node: first right child
* with its left child; then node k1 with new right child.
* For AVL trees, this is a double rotation for case 3.
*/
static BinaryNode doubleWithRightChild( BinaryNode k1 )
{
k1.right = withLeftChild( k1.right );
return withRightChild( k1 );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -