You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Binary Search Tree/README.markdown
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -412,7 +412,7 @@ To see how this works, take the following tree:
412
412
413
413

414
414
415
-
For example, if we look at node `10`, its leftmost descendent is `6`. We get there by following all the `left` pointers until there are no more left children to look at. The leftmost descendent of the root node `7` is `1`. Therefore, `1` is the minimum value in the entire tree.
415
+
For example, if we look at node `10`, its leftmost descendent is `7`. We get there by following all the `left` pointers until there are no more left children to look at. The leftmost descendent of the root node `6` is `1`. Therefore, `1` is the minimum value in the entire tree.
416
416
417
417
We won't need it for deleting, but for completeness' sake, here is the opposite of `minimum()`:
418
418
@@ -426,7 +426,7 @@ We won't need it for deleting, but for completeness' sake, here is the opposite
426
426
}
427
427
```
428
428
429
-
It returns the rightmost descendent of the node. We find it by following `right` pointers until we get to the end. In the above example, the rightmost descendent of node `2` is `5`. The maximum value in the entire tree is `11`, because that is the rightmost descendent of the root node `7`.
429
+
It returns the rightmost descendent of the node. We find it by following `right` pointers until we get to the end. In the above example, the rightmost descendent of node `2` is `5`. The maximum value in the entire tree is `11`, because that is the rightmost descendent of the root node `6`.
430
430
431
431
Finally, we can write the code that removes a node from the tree:
432
432
@@ -500,11 +500,11 @@ if let node2 = tree.search(2) {
500
500
501
501
First you find the node that you want to remove with `search()` and then you call `remove()` on that object. Before the removal, the tree printed like this:
502
502
503
-
((1) <- 2 -> (5)) <- 7 -> ((9) <- 10)
503
+
((1) <- 2 -> (5)) <- 6 -> ((9) <- 10)
504
504
505
505
But after `remove()` you get:
506
506
507
-
((1) <- 5) <- 7 -> ((9) <- 10)
507
+
((1) <- 5) <- 6 -> ((9) <- 10)
508
508
509
509
As you can see, node `5` has taken the place of `2`.
0 commit comments