Skip to content

Instantly share code, notes, and snippets.

@guillaumebihet
Last active June 25, 2018 08:50
Show Gist options
  • Save guillaumebihet/70712a1cc4f7718db6831dbd7bdcc4bb to your computer and use it in GitHub Desktop.
Save guillaumebihet/70712a1cc4f7718db6831dbd7bdcc4bb to your computer and use it in GitHub Desktop.
class Tree
attr_accessor :payload, :children
def initialize(payload, children)
@payload = payload
@children = children
end
end
#The "Leafs" of the tree, elements that have no children
deep_fifth_node = Tree.new(5,[])
eighth_node = Tree.new(8, [])
fourth_node = Tree.new(4, [])
#The "Branches"of the tree
ninth_node = Tree.new(9, [fourth_node])
sixth_node = Tree.new(6, [deep_fifth_node, eighth_node])
seventh_node = Tree.new(7, [sixth_node])
shallow_fifth_node = Tree.new(5, [ninth_node])
#The "Trunk" of the tree
trunk = Tree.new(2, [seventh_node, shallow_fifth_node])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment