QueueWorld#
QueueWorld visualizes a FIFO queue as a row of boxes growing left-to-right.
The front box (next to be dequeued) is highlighted in red;
the back box (most recently enqueued) in purple.
Operations#
Method |
Description |
|---|---|
|
Add a value to the back. Raises |
|
Remove and return the front value. Raises |
|
Return the front value without removing it. Raises |
|
Return the back value without removing it. Raises |
|
Return all current elements, front-to-back order. |
|
Return |
|
Return |
|
Remove all elements. |
|
Number of elements currently in the queue (property). |
Constructor parameters#
Parameter |
Default |
Description |
|---|---|---|
|
|
Maximum number of elements. |
|
|
Width of each element box in pixels. |
|
|
Height of each element box in pixels. |
|
|
Margin around the queue in pixels. |
|
light grey |
Background fill color. |
Example#
from miniworlds_data import QueueWorld
world = QueueWorld(capacity=5)
world.enqueue(10)
world.enqueue(20)
world.enqueue(30)
print(world.front()) # 10
print(world.dequeue()) # 10
world.run()
API Reference#
- class miniworlds_data.queue_world.QueueWorld(*, capacity=8, box_width=80, box_height=50, margin=10, background=(245, 245, 245, 255))[source]#
Pixel world that visualizes a FIFO queue growing left-to-right.
Elements are enqueued at the back and dequeued at the front. The front box is highlighted in red, the back box in purple.
Example
from miniworlds_data import QueueWorld world = QueueWorld() world.enqueue(3) world.enqueue(7) world.enqueue(2) print(world.front()) # 3 print(world.dequeue()) # 3 world.run()
- back()[source]#
Return the back element without removing it.
- Return type:
- Raises:
IndexError – when the queue is empty.
- dequeue()[source]#
Remove and return the front element.
- Return type:
- Raises:
IndexError – when the queue is empty.
- dialog#
- enqueue(value)[source]#
Add
valueto the back of the queue.- Return type:
- Raises:
OverflowError – when the queue is already at capacity.
- front()[source]#
Return the front element without removing it.
- Return type:
- Raises:
IndexError – when the queue is empty.