ListWorld#
ListWorld visualizes a list of numeric values as a row of vertical bars.
Each bar’s height is proportional to its value. Use it to animate sorting and
search algorithms step by step.
Operations#
Method |
Description |
|---|---|
|
Highlight cells |
|
Swap the values of cells |
|
Color one cell with a named state (default: |
|
Mark a cell as having reached its final sorted position ( |
|
Reset one cell back to |
|
Reset every cell to |
|
Change a cell’s value and relayout all bars. |
|
|
|
Number of cells (property). |
|
Return |
Example#
from miniworlds_data import ListWorld
world = ListWorld([8, 3, 6, 1, 4])
world.compare(0, 1) # highlight two cells yellow
world.swap(0, 1) # swap their values
world.mark_sorted(4) # mark the last position as done
world.run()
API Reference#
- class miniworlds_data.list_world.ListWorld(values=None, *, cell_width=50, bar_height=200, label_height=30, margin=10, background=(245, 245, 245, 255))#
Visualizes a list of numeric values as bars. The table above lists the public operations intended for lesson and algorithm examples.