mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-27 03:50:19 +08:00
build
This commit is contained in:
@@ -767,21 +767,21 @@ It can be observed that **the right and left rotation operations are logically s
|
||||
[class]{AVLTree}-[func]{leftRotate}
|
||||
```
|
||||
|
||||
### 3. Right-left rotation
|
||||
### 3. Left-right rotation
|
||||
|
||||
For the unbalanced node 3 shown in Figure 7-30, using either left or right rotation alone cannot restore balance to the subtree. In this case, a "left rotation" needs to be performed on `child` first, followed by a "right rotation" on `node`.
|
||||
|
||||
{ class="animation-figure" }
|
||||
{ class="animation-figure" }
|
||||
|
||||
<p align="center"> Figure 7-30 Right-left rotation </p>
|
||||
<p align="center"> Figure 7-30 Left-right rotation </p>
|
||||
|
||||
### 4. Left-right rotation
|
||||
### 4. Right-left rotation
|
||||
|
||||
As shown in Figure 7-31, for the mirror case of the above unbalanced binary tree, a "right rotation" needs to be performed on `child` first, followed by a "left rotation" on `node`.
|
||||
|
||||
{ class="animation-figure" }
|
||||
{ class="animation-figure" }
|
||||
|
||||
<p align="center"> Figure 7-31 Left-right rotation </p>
|
||||
<p align="center"> Figure 7-31 Right-left rotation </p>
|
||||
|
||||
### 5. Choice of rotation
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ A <u>binary tree</u> is a non-linear data structure that represents the hierarch
|
||||
Left *TreeNode
|
||||
Right *TreeNode
|
||||
}
|
||||
/* 构造方法 */
|
||||
/* Constructor */
|
||||
func NewTreeNode(v int) *TreeNode {
|
||||
return &TreeNode{
|
||||
Left: nil, // Pointer to left child node
|
||||
@@ -145,7 +145,7 @@ A <u>binary tree</u> is a non-linear data structure that represents the hierarch
|
||||
}
|
||||
|
||||
impl TreeNode {
|
||||
/* 构造方法 */
|
||||
/* Constructor */
|
||||
fn new(val: i32) -> Rc<RefCell<Self>> {
|
||||
Rc::new(RefCell::new(Self {
|
||||
val,
|
||||
@@ -162,12 +162,12 @@ A <u>binary tree</u> is a non-linear data structure that represents the hierarch
|
||||
/* Binary tree node */
|
||||
typedef struct TreeNode {
|
||||
int val; // Node value
|
||||
int height; // 节点高度
|
||||
int height; // Node height
|
||||
struct TreeNode *left; // Pointer to left child node
|
||||
struct TreeNode *right; // Pointer to right child node
|
||||
} TreeNode;
|
||||
|
||||
/* 构造函数 */
|
||||
/* Constructor */
|
||||
TreeNode *newTreeNode(int val) {
|
||||
TreeNode *node;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user