Last active
January 27, 2021 16:26
-
-
Save liamwhite/eb5c6f7f98d2cbd36bd86d4a5a5aa144 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
class BinaryTree | |
attr_accessor :data, :left, :right | |
def initialize(data, left, right) | |
@data = data | |
@left = left | |
@right = right | |
end | |
# Return a new tree with all the nodes reversed. | |
# | |
# For example, calling this method on a tree that | |
# looks like this | |
# | |
# (50) | |
# / \ | |
# (20) (80) | |
# / \ \ | |
# (10) (30) (90) | |
# / \ | |
# (25) (40) | |
# | |
# should return a tree that looks like this | |
# | |
# (50) | |
# / \ | |
# (80) (20) | |
# / / \ | |
# (90) (30) (10) | |
# / \ | |
# (40) (25) | |
# | |
# . | |
# | |
# You are encouraged to use recursion. | |
def mirror | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment