data_structures.queue.queue_by_list

Queue represented by a Python list

Attributes

_T

Classes

QueueByList

Module Contents

class data_structures.queue.queue_by_list.QueueByList(iterable: collections.abc.Iterable[_T] | None = None)

Bases: Generic[_T]

__len__() int
>>> len(QueueByList())
0
>>> from string import ascii_lowercase
>>> len(QueueByList(ascii_lowercase))
26
>>> queue = QueueByList()
>>> for i in range(1, 11):
...     queue.put(i)
>>> len(queue)
10
>>> for i in range(2):
...   queue.get()
1
2
>>> len(queue)
8
__repr__() str
>>> queue = QueueByList()
>>> queue
Queue(())
>>> str(queue)
'Queue(())'
>>> queue.put(10)
>>> queue
Queue((10,))
>>> queue.put(20)
>>> queue.put(30)
>>> queue
Queue((10, 20, 30))
get() _T

Get item from the Queue

>>> queue = QueueByList((10, 20, 30))
>>> queue.get()
10
>>> queue.put(40)
>>> queue.get()
20
>>> queue.get()
30
>>> len(queue)
1
>>> queue.get()
40
>>> queue.get()
Traceback (most recent call last):
    ...
IndexError: Queue is empty
get_front() _T

Get the front item from the Queue

>>> queue = QueueByList((10, 20, 30))
>>> queue.get_front()
10
>>> queue
Queue((10, 20, 30))
>>> queue.get()
10
>>> queue.get_front()
20
put(item: _T) None

Put item to the Queue

>>> queue = QueueByList()
>>> queue.put(10)
>>> queue.put(20)
>>> len(queue)
2
>>> queue
Queue((10, 20))
rotate(rotation: int) None

Rotate the items of the Queue rotation times

>>> queue = QueueByList([10, 20, 30, 40])
>>> queue
Queue((10, 20, 30, 40))
>>> queue.rotate(1)
>>> queue
Queue((20, 30, 40, 10))
>>> queue.rotate(2)
>>> queue
Queue((40, 10, 20, 30))
entries: list[_T]
data_structures.queue.queue_by_list._T