Complete the code to enqueue an element at the rear of the queue.
void enqueue(int queue[], int *rear, int value) {
queue[++(*rear)] = [1];
}The enqueue function adds the given value at the position after the current rear.
Complete the code to dequeue an element from the front of the queue.
int dequeue(int queue[], int *front, int rear) {
if (*front == -1 || *front > rear) {
return -1; // Queue is empty
}
return queue[[1]++];
}The element at the current front is returned, then front is incremented to remove it from the queue.
Fix the error in the condition that checks if the queue is full.
int isFull(int rear, int maxSize) {
return rear == [1] - 1;
}The queue is full when rear index reaches maxSize - 1, the last valid position.
Fill both blanks to correctly initialize the queue pointers.
int front = [1]; int rear = [2];
Both front and rear are initialized to -1 to indicate the queue is empty.
Fill the blanks to implement a circular queue condition to check if the queue is full.
int isFull(int front, int rear, int maxSize) {
return (rear + 1) % [1] == [2];
}In a circular queue (wasting one space to distinguish full from empty), the queue is full when (rear + 1) % maxSize == front.
