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 >>> (cq.size, cq.first
(self, data)
| 48 | return False if self.is_empty() else self.array[self.front] |
| 49 | |
| 50 | def enqueue(self, data): |
| 51 | """ |
| 52 | This function inserts an element at the end of the queue using self.rear value |
| 53 | as an index. |
| 54 | |
| 55 | >>> cq = CircularQueue(5) |
| 56 | >>> cq.enqueue("A") # doctest: +ELLIPSIS |
| 57 | <data_structures.queues.circular_queue.CircularQueue object at ...> |
| 58 | >>> (cq.size, cq.first()) |
| 59 | (1, 'A') |
| 60 | >>> cq.enqueue("B") # doctest: +ELLIPSIS |
| 61 | <data_structures.queues.circular_queue.CircularQueue object at ...> |
| 62 | >>> cq.array |
| 63 | ['A', 'B', None, None, None] |
| 64 | >>> (cq.size, cq.first()) |
| 65 | (2, 'A') |
| 66 | >>> cq.enqueue("C").enqueue("D").enqueue("E") # doctest: +ELLIPSIS |
| 67 | <data_structures.queues.circular_queue.CircularQueue object at ...> |
| 68 | >>> cq.enqueue("F") |
| 69 | Traceback (most recent call last): |
| 70 | ... |
| 71 | Exception: QUEUE IS FULL |
| 72 | """ |
| 73 | if self.size >= self.n: |
| 74 | raise Exception("QUEUE IS FULL") |
| 75 | |
| 76 | self.array[self.rear] = data |
| 77 | self.rear = (self.rear + 1) % self.n |
| 78 | self.size += 1 |
| 79 | return self |
| 80 | |
| 81 | def dequeue(self): |
| 82 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected