data_structures.queue.circular_queue_linked_list

Classes

CircularQueueLinkedList

Circular FIFO list with the given capacity (default queue length : 6)

Node

Module Contents

class data_structures.queue.circular_queue_linked_list.CircularQueueLinkedList(initial_capacity: int = 6)

Circular FIFO list with the given capacity (default queue length : 6)

>>> cq = CircularQueueLinkedList(2)
>>> cq.enqueue('a')
>>> cq.enqueue('b')
>>> cq.enqueue('c')
Traceback (most recent call last):
   ...
Exception: Full Queue
check_can_perform_operation() None
check_is_full() None
create_linked_list(initial_capacity: int) None
dequeue() Any

Removes and retrieves the first element of the queue

>>> cq = CircularQueueLinkedList()
>>> cq.dequeue()
Traceback (most recent call last):
   ...
Exception: Empty Queue
>>> cq.enqueue('a')
>>> cq.dequeue()
'a'
>>> cq.dequeue()
Traceback (most recent call last):
   ...
Exception: Empty Queue
enqueue(data: Any) None

Saves data at the end of the queue

>>> cq = CircularQueueLinkedList()
>>> cq.enqueue('a')
>>> cq.enqueue('b')
>>> cq.dequeue()
'a'
>>> cq.dequeue()
'b'
>>> cq.dequeue()
Traceback (most recent call last):
   ...
Exception: Empty Queue
first() Any | None

Returns the first element of the queue >>> cq = CircularQueueLinkedList() >>> cq.first() Traceback (most recent call last):

Exception: Empty Queue >>> cq.enqueue(‘a’) >>> cq.first() ‘a’ >>> cq.dequeue() ‘a’ >>> cq.first() Traceback (most recent call last):

Exception: Empty Queue >>> cq.enqueue(‘b’) >>> cq.enqueue(‘c’) >>> cq.first() ‘b’

is_empty() bool

Checks whether the queue is empty or not >>> cq = CircularQueueLinkedList() >>> cq.is_empty() True >>> cq.enqueue(‘a’) >>> cq.is_empty() False >>> cq.dequeue() ‘a’ >>> cq.is_empty() True

front: Node | None = None
rear: Node | None = None
class data_structures.queue.circular_queue_linked_list.Node
data: Any | None = None
next: Node | None = None
prev: Node | None = None