Created
September 17, 2013 01:17
-
-
Save dpick/6588930 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def delete(value, node = @root) | |
return if node.nil? | |
if x < node.value | |
node.left = delete(x, node.left) | |
elsif x > node.value | |
node.right = delete(x, node.right) | |
else | |
if node.left.nil? | |
return node.right | |
elsif node.right.nil? | |
return node.left | |
end | |
succesor = first_in_order(node.right) | |
node.value = successor.value | |
node.right = delete(successor.value, node.right) | |
end | |
node | |
end | |
def first_in_order(node) | |
return node if node.left.nil? | |
first_in_order(node.left) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment