Skip to content

Commit edfb5b6

Browse files
committed
Chapter 05 BST successor implementation bug fixed.
1 parent 55b645d commit edfb5b6

File tree

1 file changed

+2
-2
lines changed
  • 05-Binary-Search-Tree/Course Code (Java)/Optional-06-Predecessor-and-Successor-in-BST/src/bobo/algo

1 file changed

+2
-2
lines changed

05-Binary-Search-Tree/Course Code (Java)/Optional-06-Predecessor-and-Successor-in-BST/src/bobo/algo/BST.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ Node successorFromAncestor(Node node, Key key){
455455
assert(key.compareTo(node.key) < 0);
456456
// 如果当前节点大于key, 则当前节点有可能是比key大的最小值
457457
// 向左继续搜索, 将结果存储到tempNode中
458-
Node tempNode = predecessorFromAncestor(node.left, key);
458+
Node tempNode = successorFromAncestor(node.left, key);
459459
if(tempNode != null)
460460
return tempNode;
461461
else
@@ -480,7 +480,7 @@ public static void main(String[] args) {
480480
int pos = (int) (Math.random() * (i+1));
481481
Integer t = arr[pos];
482482
arr[pos] = arr[i];
483-
arr[i] = arr[pos];
483+
arr[i] = t;
484484
}
485485
// 由于我们实现的二分搜索树不是平衡二叉树,
486486
// 所以如果按照顺序插入一组数据,我们的二分搜索树会退化成为一个链表

0 commit comments

Comments
 (0)