On December 12, many communities celebrate the Feast of Our Lady of Guadalupe with gatherings and organized queues. In this problem, you will implement a circular queue with a fixed capacity to support common queue operations.
Implement a circular queue that adheres to the First In, First Out (FIFO) principle. Your circular queue should include the following operations:
true
if the operation is successful; otherwise, return false
.true
if the operation is successful; otherwise, return false
.-1
.-1
.true
if it is; otherwise, return false
.true
if it is; otherwise, return false
.Since the queue is circular, when the end of the queue is reached, it should wrap around to the beginning if there is available space.
MyCircularQueue circularQueue = new MyCircularQueue(3); // queue capacity is 3
circularQueue.enQueue(1); // returns true
circularQueue.enQueue(2); // returns true
circularQueue.enQueue(3); // returns true
circularQueue.enQueue(4); // returns false since the queue is full
circularQueue.Rear(); // returns 3
circularQueue.isFull(); // returns true
circularQueue.deQueue(); // returns true
circularQueue.enQueue(4); // returns true
circularQueue.Rear(); // returns 4
Below is some language-agnostic starter code outlining the class and its methods. Complete the implementation for your chosen programming language.
// MyCircularQueue class:
// Constructor: MyCircularQueue(k: number) // initializes the queue with a max size k
// enQueue(value: number): boolean
// deQueue(): boolean
// Front(): number
// Rear(): number
// isEmpty(): boolean
// isFull(): boolean