Skip to content

Instantly share code, notes, and snippets.

@liamwhite
Last active January 27, 2021 16:26
Show Gist options
  • Save liamwhite/eb5c6f7f98d2cbd36bd86d4a5a5aa144 to your computer and use it in GitHub Desktop.
Save liamwhite/eb5c6f7f98d2cbd36bd86d4a5a5aa144 to your computer and use it in GitHub Desktop.
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