Created
May 15, 2017 17:27
-
-
Save andrewsouthard1/698c15d6b41ae9f988f5e8af5c9f9e28 to your computer and use it in GitHub Desktop.
Binary Tree Class
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
class BinaryTreeNode | |
attr_accessor :value | |
attr_reader :left, :right | |
def initialize(value) | |
@value = value | |
@right = nil | |
@left = nil | |
end | |
def insert_right(value) | |
@right = BinaryTreeNode.new(value) | |
end | |
def insert_left(value) | |
@left = BinaryTreeNode.new(value) | |
end | |
end | |
a = BinaryTreeNode.new(5) | |
a.insert_left(3) | |
a.insert_right(9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment