Two Pointers
`Front` tracks the element to be popped. `Rear` tracks the element that was just pushed. Initially, both are `-1`.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Implementing a basic Queue using a statically sized array. We use two pointers, `front` and `rear`, to track the boundaries of the queue.
`Front` tracks the element to be popped. `Rear` tracks the element that was just pushed. Initially, both are `-1`.
As you push and pop, both pointers move to the right. Eventually, `rear` hits the end of the array. Even if there is empty space at the beginning (from popped elements), you can't use it! This is called "False Overflow".
This massive flaw in standard Array Queues is exactly why the Circular Queue was invented, which wraps the pointers back to 0 using modulo arithmetic.