TreeWorld and TreeNode#
TreeWorld visualizes a binary tree.
Nodes are placed via a level-order layout computed automatically by the world;
edges are drawn as lines between parent and child nodes.
Building the tree#
from miniworlds_data import TreeWorld
world = TreeWorld()
root = world.set_root(5)
left = world.add_left(root, 3)
right = world.add_right(root, 8)
world.add_left(left, 1)
world.add_right(left, 4)
world.run()
TreeWorld operations#
Method |
Description |
|---|---|
|
Create and return the root node. Can only be called once. |
|
Add a left child to |
|
Add a right child to |
|
Highlight a node with a named state. States: |
|
Color the edge between |
|
Reset all nodes and edges to their default colors. |
|
Return nodes in in-order sequence. |
|
Return nodes in pre-order sequence. |
|
Return nodes in post-order sequence. |
|
The root |
|
List of all |
TreeNode attributes#
Attribute |
Description |
|---|---|
|
The stored value. |
|
Left child |
|
Right child |
|
Current highlight state string. |
|
Change the highlight state and update the color. |