Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions data_structures/queues/circular_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __len__(self) -> int:
>>> len(cq)
0
>>> cq.enqueue("A") # doctest: +ELLIPSIS
<data_structures.queues.circular_queue.CircularQueue object at ...
<data_structures.queues.circular_queue.CircularQueue object at ...>
>>> cq.array
['A', None, None, None, None]
>>> len(cq)
Expand Down Expand Up @@ -51,17 +51,24 @@ def enqueue(self, data):
"""
This function inserts an element at the end of the queue using self.rear value
as an index.

>>> cq = CircularQueue(5)
>>> cq.enqueue("A") # doctest: +ELLIPSIS
<data_structures.queues.circular_queue.CircularQueue object at ...
<data_structures.queues.circular_queue.CircularQueue object at ...>
>>> (cq.size, cq.first())
(1, 'A')
>>> cq.enqueue("B") # doctest: +ELLIPSIS
<data_structures.queues.circular_queue.CircularQueue object at ...
<data_structures.queues.circular_queue.CircularQueue object at ...>
>>> cq.array
['A', 'B', None, None, None]
>>> (cq.size, cq.first())
(2, 'A')
>>> cq.enqueue("C").enqueue("D").enqueue("E") # doctest: +ELLIPSIS
<data_structures.queues.circular_queue.CircularQueue object at ...>
>>> cq.enqueue("F")
Traceback (most recent call last):
...
Exception: QUEUE IS FULL
"""
if self.size >= self.n:
raise Exception("QUEUE IS FULL")
Expand All @@ -75,6 +82,7 @@ def dequeue(self):
"""
This function removes an element from the queue using on self.front value as an
index and returns it

>>> cq = CircularQueue(5)
>>> cq.dequeue()
Traceback (most recent call last):
Expand Down