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

enqueue(value)

Add a value to the back. Raises OverflowError when at capacity.

dequeue()

Remove and return the front value. Raises IndexError on empty queue.

front()

Return the front value without removing it. Raises IndexError on empty queue.

back()

Return the back value without removing it. Raises IndexError on empty queue.

values()

Return all current elements, front-to-back order.

is_empty()

Return True when the queue has no elements.

is_full()

Return True when the queue has reached its capacity.

clear()

Remove all elements.

size

Number of elements currently in the queue (property).

Constructor parameters#

Parameter

Default

Description

capacity

8

Maximum number of elements.

box_width

80

Width of each element box in pixels.

box_height

50

Height of each element box in pixels.

margin

10

Margin around the queue in pixels.

background

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:

object

Raises:

IndexError – when the queue is empty.

clear()[source]#

Remove every element from the queue.

Return type:

None

dequeue()[source]#

Remove and return the front element.

Return type:

object

Raises:

IndexError – when the queue is empty.

dialog#
enqueue(value)[source]#

Add value to the back of the queue.

Return type:

None

Raises:

OverflowError – when the queue is already at capacity.

front()[source]#

Return the front element without removing it.

Return type:

object

Raises:

IndexError – when the queue is empty.

is_empty()[source]#
Return type:

bool

is_full()[source]#
Return type:

bool

property size: int#

Number of elements currently in the queue.

values()[source]#

Return the current elements, front-to-back order.

Return type:

List[object]