0.0
No release in over a year
Convert a binary tree to array and vice versa.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Binary Trees

A gem to convert a binary tree to array and vice versa.

Install

gem install binary_trees

Usage

Convert an array to TreeNode(root) and Tree

root = [1, 2, 3, 4, 5, 6].to_root
tree = Tree.new(root)

Access root value

root.val # == 1
root.left.right.val # == 5

Sum tree value

tree.sum # == 11

Convert a tree to array

tree.to_a

Invert TreeNodes (left -> right && right -> left)

tree.invert # return root [1, 3, 2, nil, 6, 5, 4]