Skip to content

Instantly share code, notes, and snippets.

@albertein
Created January 8, 2014 18:32
Show Gist options
  • Save albertein/8321868 to your computer and use it in GitHub Desktop.
Save albertein/8321868 to your computer and use it in GitHub Desktop.
nodes = []
nodes.push(root)
while (!nodes.empty?) do
node = nodes.pop()
next if node.nil?
if (node.value < min)
node.parent.replace(node, node.right)
nodes.push(node.right)
elsif (node.value > max)
node.parent.replace(node, node.left)
nodes.push(node.left)
else
node.push(node.left)
node.push(node.right)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment