A queue retrieves elements in first-in, first-out (FIFO) order: the earliest added element is removed first. Queues suit tasks where processing order matters, such as processing positions in the order a pathfinding algorithm discovers them. Enemy spawning does not need FIFO if any available enemy index will do. section 6.4
An array-backed circular queue avoids shifting elements on every removal. Track the array, the index to remove from (start), the next index to add to (end), and the number of stored elements (count). Enqueue writes at end; dequeue reads at start. Advance the relevant index after each operation, wrapping it to zero at the array’s end. section 6.4
Figure 6.12 To implement a queue using a circular array, we use two indices: start and end. If either index reaches the array limit, we reset it to the beginning. Start points to the first element added, which is 10. End points to the next empty index, the one after 40. When we dequeue, we output the first element (10), then increment start, so it now points to 20. When we enqueue 50, we write it at the current end index. Then we increment end. Since end has now reached the array limit, it wraps back to 0.

The diagram traces dequeueing 10, then enqueueing 50 as the end index wraps to the start of the array. section 6.4
A circular array keeps its elements in place, avoiding the copies required by shifting every remaining item left. This makes its behavior visible and preserves contiguous storage, but a queue maintains more state and wraparound checks than a stack. Use FIFO only when the problem requires it; otherwise, a simpler choice may suffice. section 6.4 section 6.8





























