mirror of
https://github.com/krahets/hello-algo.git
synced 2025-01-23 22:40:25 +08:00
Update the docs for the section of AVL tree and style (#351)
Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
parent
e65c7bd478
commit
1eb0d91978
@ -131,6 +131,7 @@ function testPoll(maxHeap) {
|
||||
maxHeap.print();
|
||||
}
|
||||
|
||||
/* Driver Code */
|
||||
/* 初始化大顶堆 */
|
||||
const maxHeap = new MaxHeap([9, 8, 6, 6, 7, 5, 2, 1, 4, 3, 6, 2]);
|
||||
console.log("\n输入列表并建堆后");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* File: my_heap.js
|
||||
* File: my_heap.ts
|
||||
* Created Time: 2023-02-07
|
||||
* Author: Justin (xiefahit@gmail.com)
|
||||
*/
|
||||
|
45
docs/chapter_tree/avl_tree.md
Executable file → Normal file
45
docs/chapter_tree/avl_tree.md
Executable file → Normal file
@ -875,6 +875,16 @@ AVL 树的独特之处在于「旋转 Rotation」的操作,其可 **在不影
|
||||
return root;
|
||||
}
|
||||
|
||||
/* 获取中序遍历中的下一个结点(仅适用于 root 有左子结点的情况) */
|
||||
TreeNode* getInOrderNext(TreeNode* node) {
|
||||
if (node == nullptr) return node;
|
||||
// 循环访问左子结点,直到叶结点时为最小结点,跳出
|
||||
while (node->left != nullptr) {
|
||||
node = node->left;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/* 递归删除结点(辅助函数) */
|
||||
TreeNode* removeHelper(TreeNode* node, int val) {
|
||||
if (node == nullptr) return nullptr;
|
||||
@ -965,6 +975,18 @@ AVL 树的独特之处在于「旋转 Rotation」的操作,其可 **在不影
|
||||
// 返回子树的根结点
|
||||
return node
|
||||
}
|
||||
|
||||
/* 获取中序遍历中的下一个结点(仅适用于 root 有左子结点的情况) */
|
||||
func getInOrderNext(node *TreeNode) *TreeNode {
|
||||
if node == nil {
|
||||
return node
|
||||
}
|
||||
// 循环访问左子结点,直到叶结点时为最小结点,跳出
|
||||
for node.Left != nil {
|
||||
node = node.Left
|
||||
}
|
||||
return node
|
||||
}
|
||||
```
|
||||
|
||||
=== "JavaScript"
|
||||
@ -1003,16 +1025,6 @@ AVL 树的独特之处在于「旋转 Rotation」的操作,其可 **在不影
|
||||
return node;
|
||||
}
|
||||
|
||||
/* 获取中序遍历中的下一个结点(仅适用于 root 有左子结点的情况) */
|
||||
getInOrderNext(node) {
|
||||
if (node === null) return node;
|
||||
// 循环访问左子结点,直到叶结点时为最小结点,跳出
|
||||
while (node.left !== null) {
|
||||
node = node.left;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/* 获取中序遍历中的下一个结点(仅适用于 root 有左子结点的情况) */
|
||||
getInOrderNext(node) {
|
||||
if (node === null) return node;
|
||||
@ -1137,6 +1149,19 @@ AVL 树的独特之处在于「旋转 Rotation」的操作,其可 **在不影
|
||||
// 返回子树的根结点
|
||||
return node
|
||||
}
|
||||
|
||||
/* 获取中序遍历中的下一个结点(仅适用于 root 有左子结点的情况) */
|
||||
private func getInOrderNext(node: TreeNode?) -> TreeNode? {
|
||||
var node = node
|
||||
if node == nil {
|
||||
return node
|
||||
}
|
||||
// 循环访问左子结点,直到叶结点时为最小结点,跳出
|
||||
while node?.left != nil {
|
||||
node = node?.left
|
||||
}
|
||||
return node
|
||||
}
|
||||
```
|
||||
|
||||
=== "Zig"
|
||||
|
Loading…
Reference in New Issue
Block a user