Dequeue Operation
Dequeue Operation
how it works with different iterations (calls to the function) until the
function completes.
front = 0
rear = 4
printf("\nQueue Underflow\n");
return;
}
front == -1: This checks if the queue has never had any elements.
In our case, front = 0, so the queue is not empty.
front > rear: This checks if all elements have been removed,
leaving the queue empty. In our case, front = 0 and rear = 4, so
the queue is still not empty.
item = queue[front];
if (front == rear) {
front = -1;
rear = -1;
} else {
front = front + 1;
if (front == rear): This checks if the queue will be empty after this
operation. If front and rear are the same, it means there was only one
element left.
In this case, front = 0 and rear = 4, so they are not equal. Instead, the
function increments front:
front = 1
rear = 4
front = 2
rear = 4
front = 3
rear = 4
front = 4
rear = 4
front = -1;
rear = -1;
front = -1
rear = -1
front = -1
rear = -1