I'm analyzing the following code for a long time, but still, I'm not getting this one function's one line which is as follows:
void ResizeQueue(struct DynArrayQueue* q) {
int size = q->capacity;
q->capactiy = q->capacity * 2;
q->array = realloc(q->array, q->capacity);
if (!q->array) {
printf("Memory error");
return;
}
// The doubt lines:
if (q->front > q->rear) {
for (int i = 0; i < q->front; i++) {
q->array[i + size] = q->array[i];
}
q->rear = q->rear + size;
}
}
My doubt to this above code is that, at what point in this dynamic array implementation of circular queue, the front become greater then the rear one?