Created
March 25, 2013 12:20
-
-
Save abriening/5236761 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Node = Struct.new(:value, :left, :right) | |
node = Node.new(24, Node.new(12, Node.new(10), Node.new(14)), Node.new(28, nil, Node.new(30))) | |
def values(node) | |
return [] if node.nil? | |
[values(node.left), | |
node.value, | |
values(node.right)].flatten | |
end | |
values(node) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment