Complete the code to initialize the queue array with the given size.
int[] queue = new int[[1]];The queue array is initialized with the variable size which represents the maximum number of elements the queue can hold.
Complete the code to check if the queue is empty.
return front == [1];
The queue is empty when the front index is -1, indicating no elements are present.
Fix the error in the enqueue method to correctly update the rear index.
rear = (rear + [1]) % size;To move the rear index forward by one position in a circular queue, add 1 and then take modulo with size.
Fill both blanks to correctly check if the queue is full.
return (rear + [1]) % size == [2];
The queue is full when the next position of rear (calculated by adding 1 modulo size) equals front.
Fill all three blanks to correctly dequeue an element and update front index.
if (front == [1]) { front = [2]; rear = [3]; } else { front = (front + 1) % size; }
If front equals rear, the queue has one element. After dequeue, both front and rear reset to -1 to show empty queue.
