mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-23 18:11:45 +08:00
build
This commit is contained in:
@@ -177,13 +177,13 @@ G. M. Adelson-Velsky 和 E. M. Landis 在其 1962 年发表的论文 "An algorit
|
||||
|
||||
```cpp title="avl_tree.cpp"
|
||||
/* 获取节点高度 */
|
||||
int height(TreeNode* node) {
|
||||
int height(TreeNode *node) {
|
||||
// 空节点高度为 -1 ,叶节点高度为 0
|
||||
return node == nullptr ? -1 : node->height;
|
||||
}
|
||||
|
||||
/* 更新节点高度 */
|
||||
void updateHeight(TreeNode* node) {
|
||||
void updateHeight(TreeNode *node) {
|
||||
// 节点高度等于最高子树高度 + 1
|
||||
node->height = max(height(node->left), height(node->right)) + 1;
|
||||
}
|
||||
@@ -331,7 +331,8 @@ G. M. Adelson-Velsky 和 E. M. Landis 在其 1962 年发表的论文 "An algorit
|
||||
/* 获取平衡因子 */
|
||||
int balanceFactor(TreeNode node) {
|
||||
// 空节点平衡因子为 0
|
||||
if (node == null) return 0;
|
||||
if (node == null)
|
||||
return 0;
|
||||
// 节点平衡因子 = 左子树高度 - 右子树高度
|
||||
return height(node.left) - height(node.right);
|
||||
}
|
||||
@@ -341,9 +342,10 @@ G. M. Adelson-Velsky 和 E. M. Landis 在其 1962 年发表的论文 "An algorit
|
||||
|
||||
```cpp title="avl_tree.cpp"
|
||||
/* 获取平衡因子 */
|
||||
int balanceFactor(TreeNode* node) {
|
||||
int balanceFactor(TreeNode *node) {
|
||||
// 空节点平衡因子为 0
|
||||
if (node == nullptr) return 0;
|
||||
if (node == nullptr)
|
||||
return 0;
|
||||
// 节点平衡因子 = 左子树高度 - 右子树高度
|
||||
return height(node->left) - height(node->right);
|
||||
}
|
||||
@@ -498,9 +500,9 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
|
||||
```cpp title="avl_tree.cpp"
|
||||
/* 右旋操作 */
|
||||
TreeNode* rightRotate(TreeNode* node) {
|
||||
TreeNode* child = node->left;
|
||||
TreeNode* grandChild = child->right;
|
||||
TreeNode *rightRotate(TreeNode *node) {
|
||||
TreeNode *child = node->left;
|
||||
TreeNode *grandChild = child->right;
|
||||
// 以 child 为原点,将 node 向右旋转
|
||||
child->right = node;
|
||||
node->left = grandChild;
|
||||
@@ -682,9 +684,9 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
|
||||
```cpp title="avl_tree.cpp"
|
||||
/* 左旋操作 */
|
||||
TreeNode* leftRotate(TreeNode* node) {
|
||||
TreeNode* child = node->right;
|
||||
TreeNode* grandChild = child->left;
|
||||
TreeNode *leftRotate(TreeNode *node) {
|
||||
TreeNode *child = node->right;
|
||||
TreeNode *grandChild = child->left;
|
||||
// 以 child 为原点,将 node 向左旋转
|
||||
child->left = node;
|
||||
node->right = grandChild;
|
||||
@@ -905,7 +907,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
|
||||
```cpp title="avl_tree.cpp"
|
||||
/* 执行旋转操作,使该子树重新恢复平衡 */
|
||||
TreeNode* rotate(TreeNode* node) {
|
||||
TreeNode *rotate(TreeNode *node) {
|
||||
// 获取节点 node 的平衡因子
|
||||
int _balanceFactor = balanceFactor(node);
|
||||
// 左偏树
|
||||
@@ -1201,15 +1203,16 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
|
||||
/* 递归插入节点(辅助方法) */
|
||||
TreeNode insertHelper(TreeNode node, int val) {
|
||||
if (node == null) return new TreeNode(val);
|
||||
if (node == null)
|
||||
return new TreeNode(val);
|
||||
/* 1. 查找插入位置,并插入节点 */
|
||||
if (val < node.val)
|
||||
node.left = insertHelper(node.left, val);
|
||||
else if (val > node.val)
|
||||
node.right = insertHelper(node.right, val);
|
||||
else
|
||||
return node; // 重复节点不插入,直接返回
|
||||
updateHeight(node); // 更新节点高度
|
||||
return node; // 重复节点不插入,直接返回
|
||||
updateHeight(node); // 更新节点高度
|
||||
/* 2. 执行旋转操作,使该子树重新恢复平衡 */
|
||||
node = rotate(node);
|
||||
// 返回子树的根节点
|
||||
@@ -1221,13 +1224,13 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
|
||||
```cpp title="avl_tree.cpp"
|
||||
/* 插入节点 */
|
||||
TreeNode* insert(int val) {
|
||||
TreeNode *insert(int val) {
|
||||
root = insertHelper(root, val);
|
||||
return root;
|
||||
}
|
||||
|
||||
/* 递归插入节点(辅助方法) */
|
||||
TreeNode* insertHelper(TreeNode* node, int val) {
|
||||
TreeNode *insertHelper(TreeNode *node, int val) {
|
||||
if (node == nullptr)
|
||||
return new TreeNode(val);
|
||||
/* 1. 查找插入位置,并插入节点 */
|
||||
@@ -1236,8 +1239,8 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
else if (val > node->val)
|
||||
node->right = insertHelper(node->right, val);
|
||||
else
|
||||
return node; // 重复节点不插入,直接返回
|
||||
updateHeight(node); // 更新节点高度
|
||||
return node; // 重复节点不插入,直接返回
|
||||
updateHeight(node); // 更新节点高度
|
||||
/* 2. 执行旋转操作,使该子树重新恢复平衡 */
|
||||
node = rotate(node);
|
||||
// 返回子树的根节点
|
||||
@@ -1472,7 +1475,8 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
|
||||
/* 递归删除节点(辅助方法) */
|
||||
TreeNode removeHelper(TreeNode node, int val) {
|
||||
if (node == null) return null;
|
||||
if (node == null)
|
||||
return null;
|
||||
/* 1. 查找节点,并删除之 */
|
||||
if (val < node.val)
|
||||
node.left = removeHelper(node.left, val);
|
||||
@@ -1494,7 +1498,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
node.val = temp.val;
|
||||
}
|
||||
}
|
||||
updateHeight(node); // 更新节点高度
|
||||
updateHeight(node); // 更新节点高度
|
||||
/* 2. 执行旋转操作,使该子树重新恢复平衡 */
|
||||
node = rotate(node);
|
||||
// 返回子树的根节点
|
||||
@@ -1503,7 +1507,8 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
|
||||
/* 获取中序遍历中的下一个节点(仅适用于 root 有左子节点的情况) */
|
||||
TreeNode getInOrderNext(TreeNode node) {
|
||||
if (node == null) return node;
|
||||
if (node == null)
|
||||
return node;
|
||||
// 循环访问左子节点,直到叶节点时为最小节点,跳出
|
||||
while (node.left != null) {
|
||||
node = node.left;
|
||||
@@ -1516,13 +1521,13 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
|
||||
```cpp title="avl_tree.cpp"
|
||||
/* 删除节点 */
|
||||
TreeNode* remove(int val) {
|
||||
TreeNode *remove(int val) {
|
||||
root = removeHelper(root, val);
|
||||
return root;
|
||||
}
|
||||
|
||||
/* 递归删除节点(辅助方法) */
|
||||
TreeNode* removeHelper(TreeNode* node, int val) {
|
||||
TreeNode *removeHelper(TreeNode *node, int val) {
|
||||
if (node == nullptr)
|
||||
return nullptr;
|
||||
/* 1. 查找节点,并删除之 */
|
||||
@@ -1532,7 +1537,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
node->right = removeHelper(node->right, val);
|
||||
else {
|
||||
if (node->left == nullptr || node->right == nullptr) {
|
||||
TreeNode* child = node->left != nullptr ? node->left : node->right;
|
||||
TreeNode *child = node->left != nullptr ? node->left : node->right;
|
||||
// 子节点数量 = 0 ,直接删除 node 并返回
|
||||
if (child == nullptr) {
|
||||
delete node;
|
||||
@@ -1545,13 +1550,13 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
}
|
||||
} else {
|
||||
// 子节点数量 = 2 ,则将中序遍历的下个节点删除,并用该节点替换当前节点
|
||||
TreeNode* temp = getInOrderNext(node->right);
|
||||
TreeNode *temp = getInOrderNext(node->right);
|
||||
int tempVal = temp->val;
|
||||
node->right = removeHelper(node->right, temp->val);
|
||||
node->val = tempVal;
|
||||
}
|
||||
}
|
||||
updateHeight(node); // 更新节点高度
|
||||
updateHeight(node); // 更新节点高度
|
||||
/* 2. 执行旋转操作,使该子树重新恢复平衡 */
|
||||
node = rotate(node);
|
||||
// 返回子树的根节点
|
||||
@@ -1559,7 +1564,7 @@ AVL 树的特点在于「旋转 Rotation」操作,它能够在不影响二叉
|
||||
}
|
||||
|
||||
/* 获取中序遍历中的下一个节点(仅适用于 root 有左子节点的情况) */
|
||||
TreeNode* getInOrderNext(TreeNode* node) {
|
||||
TreeNode *getInOrderNext(TreeNode *node) {
|
||||
if (node == nullptr)
|
||||
return node;
|
||||
// 循环访问左子节点,直到叶节点时为最小节点,跳出
|
||||
|
||||
@@ -46,11 +46,14 @@ comments: true
|
||||
// 循环查找,越过叶节点后跳出
|
||||
while (cur != null) {
|
||||
// 目标节点在 cur 的右子树中
|
||||
if (cur.val < num) cur = cur.right;
|
||||
if (cur.val < num)
|
||||
cur = cur.right;
|
||||
// 目标节点在 cur 的左子树中
|
||||
else if (cur.val > num) cur = cur.left;
|
||||
else if (cur.val > num)
|
||||
cur = cur.left;
|
||||
// 找到目标节点,跳出循环
|
||||
else break;
|
||||
else
|
||||
break;
|
||||
}
|
||||
// 返回目标节点
|
||||
return cur;
|
||||
@@ -61,16 +64,19 @@ comments: true
|
||||
|
||||
```cpp title="binary_search_tree.cpp"
|
||||
/* 查找节点 */
|
||||
TreeNode* search(int num) {
|
||||
TreeNode* cur = root;
|
||||
TreeNode *search(int num) {
|
||||
TreeNode *cur = root;
|
||||
// 循环查找,越过叶节点后跳出
|
||||
while (cur != nullptr) {
|
||||
// 目标节点在 cur 的右子树中
|
||||
if (cur->val < num) cur = cur->right;
|
||||
if (cur->val < num)
|
||||
cur = cur->right;
|
||||
// 目标节点在 cur 的左子树中
|
||||
else if (cur->val > num) cur = cur->left;
|
||||
else if (cur->val > num)
|
||||
cur = cur->left;
|
||||
// 找到目标节点,跳出循环
|
||||
else break;
|
||||
else
|
||||
break;
|
||||
}
|
||||
// 返回目标节点
|
||||
return cur;
|
||||
@@ -259,22 +265,28 @@ comments: true
|
||||
/* 插入节点 */
|
||||
TreeNode insert(int num) {
|
||||
// 若树为空,直接提前返回
|
||||
if (root == null) return null;
|
||||
if (root == null)
|
||||
return null;
|
||||
TreeNode cur = root, pre = null;
|
||||
// 循环查找,越过叶节点后跳出
|
||||
while (cur != null) {
|
||||
// 找到重复节点,直接返回
|
||||
if (cur.val == num) return null;
|
||||
if (cur.val == num)
|
||||
return null;
|
||||
pre = cur;
|
||||
// 插入位置在 cur 的右子树中
|
||||
if (cur.val < num) cur = cur.right;
|
||||
if (cur.val < num)
|
||||
cur = cur.right;
|
||||
// 插入位置在 cur 的左子树中
|
||||
else cur = cur.left;
|
||||
else
|
||||
cur = cur.left;
|
||||
}
|
||||
// 插入节点 val
|
||||
TreeNode node = new TreeNode(num);
|
||||
if (pre.val < num) pre.right = node;
|
||||
else pre.left = node;
|
||||
if (pre.val < num)
|
||||
pre.right = node;
|
||||
else
|
||||
pre.left = node;
|
||||
return node;
|
||||
}
|
||||
```
|
||||
@@ -283,24 +295,30 @@ comments: true
|
||||
|
||||
```cpp title="binary_search_tree.cpp"
|
||||
/* 插入节点 */
|
||||
TreeNode* insert(int num) {
|
||||
TreeNode *insert(int num) {
|
||||
// 若树为空,直接提前返回
|
||||
if (root == nullptr) return nullptr;
|
||||
if (root == nullptr)
|
||||
return nullptr;
|
||||
TreeNode *cur = root, *pre = nullptr;
|
||||
// 循环查找,越过叶节点后跳出
|
||||
while (cur != nullptr) {
|
||||
// 找到重复节点,直接返回
|
||||
if (cur->val == num) return nullptr;
|
||||
if (cur->val == num)
|
||||
return nullptr;
|
||||
pre = cur;
|
||||
// 插入位置在 cur 的右子树中
|
||||
if (cur->val < num) cur = cur->right;
|
||||
if (cur->val < num)
|
||||
cur = cur->right;
|
||||
// 插入位置在 cur 的左子树中
|
||||
else cur = cur->left;
|
||||
else
|
||||
cur = cur->left;
|
||||
}
|
||||
// 插入节点 val
|
||||
TreeNode* node = new TreeNode(num);
|
||||
if (pre->val < num) pre->right = node;
|
||||
else pre->left = node;
|
||||
TreeNode *node = new TreeNode(num);
|
||||
if (pre->val < num)
|
||||
pre->right = node;
|
||||
else
|
||||
pre->left = node;
|
||||
return node;
|
||||
}
|
||||
```
|
||||
@@ -588,27 +606,34 @@ comments: true
|
||||
/* 删除节点 */
|
||||
TreeNode remove(int num) {
|
||||
// 若树为空,直接提前返回
|
||||
if (root == null) return null;
|
||||
if (root == null)
|
||||
return null;
|
||||
TreeNode cur = root, pre = null;
|
||||
// 循环查找,越过叶节点后跳出
|
||||
while (cur != null) {
|
||||
// 找到待删除节点,跳出循环
|
||||
if (cur.val == num) break;
|
||||
if (cur.val == num)
|
||||
break;
|
||||
pre = cur;
|
||||
// 待删除节点在 cur 的右子树中
|
||||
if (cur.val < num) cur = cur.right;
|
||||
if (cur.val < num)
|
||||
cur = cur.right;
|
||||
// 待删除节点在 cur 的左子树中
|
||||
else cur = cur.left;
|
||||
else
|
||||
cur = cur.left;
|
||||
}
|
||||
// 若无待删除节点,则直接返回
|
||||
if (cur == null) return null;
|
||||
if (cur == null)
|
||||
return null;
|
||||
// 子节点数量 = 0 or 1
|
||||
if (cur.left == null || cur.right == null) {
|
||||
// 当子节点数量 = 0 / 1 时, child = null / 该子节点
|
||||
TreeNode child = cur.left != null ? cur.left : cur.right;
|
||||
// 删除节点 cur
|
||||
if (pre.left == cur) pre.left = child;
|
||||
else pre.right = child;
|
||||
if (pre.left == cur)
|
||||
pre.left = child;
|
||||
else
|
||||
pre.right = child;
|
||||
}
|
||||
// 子节点数量 = 2
|
||||
else {
|
||||
@@ -625,7 +650,8 @@ comments: true
|
||||
|
||||
/* 获取中序遍历中的下一个节点(仅适用于 root 有左子节点的情况) */
|
||||
TreeNode getInOrderNext(TreeNode root) {
|
||||
if (root == null) return root;
|
||||
if (root == null)
|
||||
return root;
|
||||
// 循环访问左子节点,直到叶节点时为最小节点,跳出
|
||||
while (root.left != null) {
|
||||
root = root.left;
|
||||
@@ -638,36 +664,43 @@ comments: true
|
||||
|
||||
```cpp title="binary_search_tree.cpp"
|
||||
/* 删除节点 */
|
||||
TreeNode* remove(int num) {
|
||||
TreeNode *remove(int num) {
|
||||
// 若树为空,直接提前返回
|
||||
if (root == nullptr) return nullptr;
|
||||
if (root == nullptr)
|
||||
return nullptr;
|
||||
TreeNode *cur = root, *pre = nullptr;
|
||||
// 循环查找,越过叶节点后跳出
|
||||
while (cur != nullptr) {
|
||||
// 找到待删除节点,跳出循环
|
||||
if (cur->val == num) break;
|
||||
if (cur->val == num)
|
||||
break;
|
||||
pre = cur;
|
||||
// 待删除节点在 cur 的右子树中
|
||||
if (cur->val < num) cur = cur->right;
|
||||
if (cur->val < num)
|
||||
cur = cur->right;
|
||||
// 待删除节点在 cur 的左子树中
|
||||
else cur = cur->left;
|
||||
else
|
||||
cur = cur->left;
|
||||
}
|
||||
// 若无待删除节点,则直接返回
|
||||
if (cur == nullptr) return nullptr;
|
||||
if (cur == nullptr)
|
||||
return nullptr;
|
||||
// 子节点数量 = 0 or 1
|
||||
if (cur->left == nullptr || cur->right == nullptr) {
|
||||
// 当子节点数量 = 0 / 1 时, child = nullptr / 该子节点
|
||||
TreeNode* child = cur->left != nullptr ? cur->left : cur->right;
|
||||
TreeNode *child = cur->left != nullptr ? cur->left : cur->right;
|
||||
// 删除节点 cur
|
||||
if (pre->left == cur) pre->left = child;
|
||||
else pre->right = child;
|
||||
if (pre->left == cur)
|
||||
pre->left = child;
|
||||
else
|
||||
pre->right = child;
|
||||
// 释放内存
|
||||
delete cur;
|
||||
}
|
||||
// 子节点数量 = 2
|
||||
else {
|
||||
// 获取中序遍历中 cur 的下一个节点
|
||||
TreeNode* nex = getInOrderNext(cur->right);
|
||||
TreeNode *nex = getInOrderNext(cur->right);
|
||||
int tmp = nex->val;
|
||||
// 递归删除节点 nex
|
||||
remove(nex->val);
|
||||
@@ -678,8 +711,9 @@ comments: true
|
||||
}
|
||||
|
||||
/* 获取中序遍历中的下一个节点(仅适用于 root 有左子节点的情况) */
|
||||
TreeNode* getInOrderNext(TreeNode* root) {
|
||||
if (root == nullptr) return root;
|
||||
TreeNode *getInOrderNext(TreeNode *root) {
|
||||
if (root == nullptr)
|
||||
return root;
|
||||
// 循环访问左子节点,直到叶节点时为最小节点,跳出
|
||||
while (root->left != nullptr) {
|
||||
root = root->left;
|
||||
|
||||
@@ -32,12 +32,12 @@ comments: true
|
||||
// 初始化一个列表,用于保存遍历序列
|
||||
List<Integer> list = new ArrayList<>();
|
||||
while (!queue.isEmpty()) {
|
||||
TreeNode node = queue.poll(); // 队列出队
|
||||
list.add(node.val); // 保存节点值
|
||||
TreeNode node = queue.poll(); // 队列出队
|
||||
list.add(node.val); // 保存节点值
|
||||
if (node.left != null)
|
||||
queue.offer(node.left); // 左子节点入队
|
||||
queue.offer(node.left); // 左子节点入队
|
||||
if (node.right != null)
|
||||
queue.offer(node.right); // 右子节点入队
|
||||
queue.offer(node.right); // 右子节点入队
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -47,18 +47,18 @@ comments: true
|
||||
|
||||
```cpp title="binary_tree_bfs.cpp"
|
||||
/* 层序遍历 */
|
||||
vector<int> levelOrder(TreeNode* root) {
|
||||
vector<int> levelOrder(TreeNode *root) {
|
||||
// 初始化队列,加入根节点
|
||||
queue<TreeNode*> queue;
|
||||
queue<TreeNode *> queue;
|
||||
queue.push(root);
|
||||
// 初始化一个列表,用于保存遍历序列
|
||||
vector<int> vec;
|
||||
while (!queue.empty()) {
|
||||
TreeNode* node = queue.front();
|
||||
queue.pop(); // 队列出队
|
||||
vec.push_back(node->val); // 保存节点值
|
||||
TreeNode *node = queue.front();
|
||||
queue.pop(); // 队列出队
|
||||
vec.push_back(node->val); // 保存节点值
|
||||
if (node->left != nullptr)
|
||||
queue.push(node->left); // 左子节点入队
|
||||
queue.push(node->left); // 左子节点入队
|
||||
if (node->right != nullptr)
|
||||
queue.push(node->right); // 右子节点入队
|
||||
}
|
||||
@@ -277,7 +277,8 @@ comments: true
|
||||
```java title="binary_tree_dfs.java"
|
||||
/* 前序遍历 */
|
||||
void preOrder(TreeNode root) {
|
||||
if (root == null) return;
|
||||
if (root == null)
|
||||
return;
|
||||
// 访问优先级:根节点 -> 左子树 -> 右子树
|
||||
list.add(root.val);
|
||||
preOrder(root.left);
|
||||
@@ -286,7 +287,8 @@ comments: true
|
||||
|
||||
/* 中序遍历 */
|
||||
void inOrder(TreeNode root) {
|
||||
if (root == null) return;
|
||||
if (root == null)
|
||||
return;
|
||||
// 访问优先级:左子树 -> 根节点 -> 右子树
|
||||
inOrder(root.left);
|
||||
list.add(root.val);
|
||||
@@ -295,7 +297,8 @@ comments: true
|
||||
|
||||
/* 后序遍历 */
|
||||
void postOrder(TreeNode root) {
|
||||
if (root == null) return;
|
||||
if (root == null)
|
||||
return;
|
||||
// 访问优先级:左子树 -> 右子树 -> 根节点
|
||||
postOrder(root.left);
|
||||
postOrder(root.right);
|
||||
@@ -307,8 +310,9 @@ comments: true
|
||||
|
||||
```cpp title="binary_tree_dfs.cpp"
|
||||
/* 前序遍历 */
|
||||
void preOrder(TreeNode* root) {
|
||||
if (root == nullptr) return;
|
||||
void preOrder(TreeNode *root) {
|
||||
if (root == nullptr)
|
||||
return;
|
||||
// 访问优先级:根节点 -> 左子树 -> 右子树
|
||||
vec.push_back(root->val);
|
||||
preOrder(root->left);
|
||||
@@ -316,8 +320,9 @@ comments: true
|
||||
}
|
||||
|
||||
/* 中序遍历 */
|
||||
void inOrder(TreeNode* root) {
|
||||
if (root == nullptr) return;
|
||||
void inOrder(TreeNode *root) {
|
||||
if (root == nullptr)
|
||||
return;
|
||||
// 访问优先级:左子树 -> 根节点 -> 右子树
|
||||
inOrder(root->left);
|
||||
vec.push_back(root->val);
|
||||
@@ -325,8 +330,9 @@ comments: true
|
||||
}
|
||||
|
||||
/* 后序遍历 */
|
||||
void postOrder(TreeNode* root) {
|
||||
if (root == nullptr) return;
|
||||
void postOrder(TreeNode *root) {
|
||||
if (root == nullptr)
|
||||
return;
|
||||
// 访问优先级:左子树 -> 右子树 -> 根节点
|
||||
postOrder(root->left);
|
||||
postOrder(root->right);
|
||||
|
||||
Reference in New Issue
Block a user