data_structures.queues.circular_queue ===================================== .. py:module:: data_structures.queues.circular_queue Classes ------- .. autoapisummary:: data_structures.queues.circular_queue.CircularQueue Module Contents --------------- .. py:class:: CircularQueue(n: int) Circular FIFO queue with a fixed capacity .. py:method:: __len__() -> int >>> cq = CircularQueue(5) >>> len(cq) 0 >>> cq.enqueue("A") # doctest: +ELLIPSIS >> cq.array ['A', None, None, None, None] >>> len(cq) 1 .. py:method:: dequeue() 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): ... Exception: UNDERFLOW >>> cq.enqueue("A").enqueue("B").dequeue() 'A' >>> (cq.size, cq.first()) (1, 'B') >>> cq.dequeue() 'B' >>> cq.dequeue() Traceback (most recent call last): ... Exception: UNDERFLOW .. py:method:: enqueue(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 >> (cq.size, cq.first()) (1, 'A') >>> cq.enqueue("B") # doctest: +ELLIPSIS >> cq.array ['A', 'B', None, None, None] >>> (cq.size, cq.first()) (2, 'A') .. py:method:: first() Returns the first element of the queue >>> cq = CircularQueue(5) >>> cq.first() False >>> cq.enqueue("A").first() 'A' .. py:method:: is_empty() -> bool Checks whether the queue is empty or not >>> cq = CircularQueue(5) >>> cq.is_empty() True >>> cq.enqueue("A").is_empty() False .. py:attribute:: array .. py:attribute:: front :value: 0 .. py:attribute:: n .. py:attribute:: rear :value: 0 .. py:attribute:: size :value: 0