diff options
| author | mo <mokha@cisco.com> | 2017-08-15 20:35:34 -0600 |
|---|---|---|
| committer | mo <mokha@cisco.com> | 2017-08-15 20:35:34 -0600 |
| commit | dd4975c6d23e9db7cc5ae407872ed554973fa6f4 (patch) | |
| tree | 778570547fa7146a56c4df66ee28083344edb9ee | |
| parent | f41c59cd50b4550145ad6366f9d0df4cf131b59d (diff) | |
min -> max
| -rw-r--r-- | spec/binary_trees/delete_from_bst_spec.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/spec/binary_trees/delete_from_bst_spec.rb b/spec/binary_trees/delete_from_bst_spec.rb index 22998c0..4f705be 100644 --- a/spec/binary_trees/delete_from_bst_spec.rb +++ b/spec/binary_trees/delete_from_bst_spec.rb @@ -125,6 +125,11 @@ describe "#delete_from_bst" do If t' has a left subtree, remove the rightmost node from it and put it at the root of t'; Otherwise, remove the root of t' and its right subtree becomes the new t's root. + If t' has a left subtree and the left subtree has a child on the right, + the node you should put at the root of t' is the rightmost node (not necessarily leaf) in this subtree. + When you remove the rightmost node, you must also discard its children + (rather than keeping them as children of the rightmost node's parent). + 3 / \ 2 5 @@ -160,9 +165,9 @@ remove 1 elsif tree.right.nil? return tree.left else - min = tree.left - min = min.right while min.right - tree.value = min.value + max = tree.left + max = max.right while max.right + tree.value = max.value tree.left = remove(tree.left, tree.value) end end |
