Merge branch 'master' into binary_search_tree

This commit is contained in:
Yudong Jin
2023-01-10 13:30:38 +08:00
committed by GitHub
215 changed files with 5618 additions and 1642 deletions

View File

@@ -35,11 +35,7 @@ namespace hello_algo.chapter_tree
return root;
}
/// <summary>
/// 查找结点
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
/* 查找结点 */
public TreeNode? search(int num)
{
TreeNode? cur = root;
@@ -125,7 +121,7 @@ namespace hello_algo.chapter_tree
else
{
// 获取中序遍历中 cur 的下一个结点
TreeNode? nex = min(cur.right);
TreeNode? nex = getInOrderNext(cur.right);
if (nex != null)
{
int tmp = nex.val;
@@ -138,8 +134,8 @@ namespace hello_algo.chapter_tree
return cur;
}
/* 获取最小结点 */
private TreeNode? min(TreeNode? root)
/* 获取中序遍历中的下一个结点(仅适用于 root 有左子结点的情况) */
private TreeNode? getInOrderNext(TreeNode? root)
{
if (root == null) return root;
// 循环访问左子结点,直到叶结点时为最小结点,跳出