Skip to content

QueeniePeng/binary_trees

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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]

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages