This commit is contained in:
krahets
2024-03-31 03:53:04 +08:00
parent 87af663929
commit c23e576da4
68 changed files with 2139 additions and 22 deletions

View File

@@ -211,6 +211,17 @@ AVL 树既是二叉搜索树,也是平衡二叉树,同时满足这两类二
=== "Kotlin"
```kotlin title=""
/* AVL 树节点类 */
class TreeNode(val _val: Int) { // 节点值
val height: Int = 0 // 节点高度
val left: TreeNode? = null // 左子节点
val right: TreeNode? = null // 右子节点
}
```
=== "Ruby"
```ruby title=""
```
@@ -441,6 +452,14 @@ AVL 树既是二叉搜索树,也是平衡二叉树,同时满足这两类二
}
```
=== "Ruby"
```ruby title="avl_tree.rb"
[class]{AVLTree}-[func]{height}
[class]{AVLTree}-[func]{update_height}
```
=== "Zig"
```zig title="avl_tree.zig"
@@ -616,6 +635,12 @@ AVL 树既是二叉搜索树,也是平衡二叉树,同时满足这两类二
}
```
=== "Ruby"
```ruby title="avl_tree.rb"
[class]{AVLTree}-[func]{balance_factor}
```
=== "Zig"
```zig title="avl_tree.zig"
@@ -885,6 +910,12 @@ AVL 树的特点在于“旋转”操作,它能够在不影响二叉树的中
}
```
=== "Ruby"
```ruby title="avl_tree.rb"
[class]{AVLTree}-[func]{right_rotate}
```
=== "Zig"
```zig title="avl_tree.zig"
@@ -1140,6 +1171,12 @@ AVL 树的特点在于“旋转”操作,它能够在不影响二叉树的中
}
```
=== "Ruby"
```ruby title="avl_tree.rb"
[class]{AVLTree}-[func]{left_rotate}
```
=== "Zig"
```zig title="avl_tree.zig"
@@ -1608,6 +1645,12 @@ AVL 树的特点在于“旋转”操作,它能够在不影响二叉树的中
}
```
=== "Ruby"
```ruby title="avl_tree.rb"
[class]{AVLTree}-[func]{rotate}
```
=== "Zig"
```zig title="avl_tree.zig"
@@ -1991,6 +2034,14 @@ AVL 树的节点插入操作与二叉搜索树在主体上类似。唯一的区
}
```
=== "Ruby"
```ruby title="avl_tree.rb"
[class]{AVLTree}-[func]{insert}
[class]{AVLTree}-[func]{insert_helper}
```
=== "Zig"
```zig title="avl_tree.zig"
@@ -2576,6 +2627,14 @@ AVL 树的节点插入操作与二叉搜索树在主体上类似。唯一的区
}
```
=== "Ruby"
```ruby title="avl_tree.rb"
[class]{AVLTree}-[func]{remove}
[class]{AVLTree}-[func]{remove_helper}
```
=== "Zig"
```zig title="avl_tree.zig"