data_structures.queue.linked_queue

A Queue using a linked list like structure

Classes

LinkedQueue

Node

Module Contents

class data_structures.queue.linked_queue.LinkedQueue
>>> queue = LinkedQueue()
>>> queue.is_empty()
True
>>> queue.put(5)
>>> queue.put(9)
>>> queue.put('python')
>>> queue.is_empty()
False
>>> queue.get()
5
>>> queue.put('algorithms')
>>> queue.get()
9
>>> queue.get()
'python'
>>> queue.get()
'algorithms'
>>> queue.is_empty()
True
>>> queue.get()
Traceback (most recent call last):
    ...
IndexError: dequeue from empty queue
__iter__() collections.abc.Iterator[Any]
__len__() int
>>> queue = LinkedQueue()
>>> for i in range(1, 6):
...     queue.put(i)
>>> len(queue)
5
>>> for i in range(1, 6):
...     assert len(queue) == 6 - i
...     _ = queue.get()
>>> len(queue)
0
__str__() str
>>> queue = LinkedQueue()
>>> for i in range(1, 4):
...     queue.put(i)
>>> queue.put("Python")
>>> queue.put(3.14)
>>> queue.put(True)
>>> str(queue)
'1 <- 2 <- 3 <- Python <- 3.14 <- True'
clear() None
>>> queue = LinkedQueue()
>>> for i in range(1, 6):
...     queue.put(i)
>>> queue.clear()
>>> len(queue)
0
>>> str(queue)
''
get() Any
>>> queue = LinkedQueue()
>>> queue.get()
Traceback (most recent call last):
    ...
IndexError: dequeue from empty queue
>>> queue = LinkedQueue()
>>> for i in range(1, 6):
...     queue.put(i)
>>> for i in range(1, 6):
...     assert queue.get() == i
>>> len(queue)
0
is_empty() bool
>>> queue = LinkedQueue()
>>> queue.is_empty()
True
>>> for i in range(1, 6):
...     queue.put(i)
>>> queue.is_empty()
False
put(item: Any) None
>>> queue = LinkedQueue()
>>> queue.get()
Traceback (most recent call last):
    ...
IndexError: dequeue from empty queue
>>> for i in range(1, 6):
...     queue.put(i)
>>> str(queue)
'1 <- 2 <- 3 <- 4 <- 5'
front: Node | None = None
rear: Node | None = None
class data_structures.queue.linked_queue.Node(data: Any)
__str__() str
data: Any
next: Node | None = None