Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/binary_trees.rb
Instance Method Summary collapse
Instance Method Details
#to_tree(i = 0) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/binary_trees.rb', line 2 def to_tree(i = 0) root = nil if i < self.length root = TreeNode.new(self[i]) root.left = to_tree(i * 2 + 1) root.right = to_tree(i * 2 + 2) end root end |