Created
April 28, 2014 18:47
-
-
Save sdevani/11380620 to your computer and use it in GitHub Desktop.
On the way to building a tree
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 Tree | |
def initialize | |
@root = nil | |
end | |
def add_node(value) | |
end | |
def ensure_consistency(node) | |
if node.nil? | |
return true | |
end | |
if (node.left.value < node.value || node.right.value < node.value) || | |
(node.left_children_count - node.right_children_count).abs > 1 | |
return false | |
else | |
return ensure_consistency(node.left) && ensure_consistency(node.right) | |
end | |
end | |
def remove_top_node | |
end | |
class Node | |
attr_accessor :left, :right, :value, :left_children_count, :right_children_count | |
def initialize(value) | |
@left_children_count = 0 | |
@right_children_count = 0 | |
@value = value | |
@left = nil | |
@right = nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment