TheAlgorithms/Python · error · Exception
Full Queue
Error message
Full Queue
What it means
CircularQueueLinkedList.check_is_full raises a generic Exception('Full Queue') when rear.next == front — the pre-allocated ring of Nodes is fully occupied and enqueue would overwrite the oldest item. enqueue() calls it before advancing rear, so the raised call leaves the queue state unchanged.
Source
Thrown at data_structures/queues/circular_queue_linked_list.py:148
return None
if self.front == self.rear:
data = self.front.data
self.front.data = None
return data
old_front = self.front
self.front = old_front.next
data = old_front.data
old_front.data = None
return data
def check_can_perform_operation(self) -> None:
if self.is_empty():
raise Exception("Empty Queue")
def check_is_full(self) -> None:
if self.rear and self.rear.next == self.front:
raise Exception("Full Queue")
class Node:
def __init__(self) -> None:
self.data: Any | None = None
self.next: Node | None = None
self.prev: Node | None = None
if __name__ == "__main__":
import doctest
doctest.testmod()
View on GitHub (pinned to f5988cc097)
Solutions
- Track occupancy on the caller side or compare against initial_capacity before enqueueing.
- Dequeue one item before each enqueue once full (single-slot rotation).
- Construct the queue with capacity >= maximum concurrent items, e.g. len(burst)+1 headroom.
Example fix
# before
cq.enqueue(item) # Exception: Full Queue
# after
if cq.rear and cq.rear.next == cq.front:
cq.dequeue() # make room
cq.enqueue(item) Defensive patterns
Strategy: validation
Validate before calling
def enqueue(cq, item):
if cq.rear and cq.rear.next == cq.front:
cq.dequeue() # recycle the oldest slot
cq.enqueue(item) Try / catch
try:
cq.enqueue(item)
except Exception as e:
if 'Full Queue' not in str(e):
raise
cq.dequeue()
cq.enqueue(item) Prevention
- Track enqueued-minus-dequeued count against initial_capacity (default 6).
- Construct with capacity sized to peak occupancy plus headroom.
- enqueue is not idempotent on failure — the check fires before state changes.
When it happens
Trigger: Enqueueing more items than the initial_capacity passed to the constructor (default 6) without dequeuing; e.g. capacity 2 with a third enqueue, as in the class doctest.
Common situations: Throughput mismatch between producer and consumer on a fixed-size ring; constructor capacity copied from an old spec while payload volume grew; assuming the queue grows dynamically like list-based queues.
Related errors
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/b13eaaf17590a9f5.
Report an issue: GitHub.