β¨ Construct
Construct Binary Tree from a list.
Binary Tree Construct Methods
Construct Binary Tree from | Using heapq structure | Add node attributes |
---|---|---|
List | list_to_binarytree |
No |
bigtree.binarytree.construct
list_to_binarytree
Construct tree from a list of numbers (int or float) in heapq format.
Examples:
>>> from bigtree import list_to_binarytree, tree_to_dot
>>> nums_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> root = list_to_binarytree(nums_list)
>>> root.show()
1
βββ 2
β βββ 4
β β βββ 8
β β βββ 9
β βββ 5
β βββ 10
βββ 3
βββ 6
βββ 7
>>> graph = tree_to_dot(root, node_colour="gold")
>>> graph.write_png("assets/construct_binarytree.png")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
heapq_list |
List[int]
|
list containing integer node names, ordered in heapq fashion |
required |
node_type |
Type[BinaryNode]
|
node type of tree to be created, defaults to |
BinaryNode
|
Returns:
Type | Description |
---|---|
BinaryNode
|
(BinaryNode) |