Complete the code to initialize the front index of the queue.
int front = [1];The front index is initialized to -1 to indicate the queue is empty.
Complete the code to check if the queue is full.
if (rear == [1] - 1) { printf("Queue is full\n"); }
The queue is full when rear reaches MAX_SIZE - 1, the last index of the array.
Fix the error in the enqueue function to correctly add an element.
void enqueue(int queue[], int *rear, int value) {
if (*rear == MAX_SIZE - 1) {
printf("Queue is full\n");
} else {
*rear = *rear [1] 1;
queue[*rear] = value;
}
}To add an element, increment rear by 1 before assigning the value.
Fill the blank to correctly dequeue an element and update front.
int dequeue(int queue[], int *front, int rear) {
if (*front == rear) {
printf("Queue is empty\n");
return -1;
} else {
*front = *front [1] 1;
return queue[*front];
}
}Increment front by 1 to remove the front element and return it.
Fill all three blanks to implement a function that prints all elements in the queue.
void printQueue(int queue[], int front, int rear) {
if (front == rear) {
printf("Queue is empty\n");
} else {
for (int i = front [1] 1; i [2] rear; i [3] 1) {
printf("%d -> ", queue[i]);
}
printf("NULL\n");
}
}The loop starts from front + 1, runs while i < rear, and increments i by 1 each time to print all elements.
