Linear Crawl
In a standard array implementation, both the `front` and `rear` pointers start at `-1`. As you enqueue and dequeue, both pointers strictly move forward (to the right). They never move backward!
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Before writing code, it's crucial to understand the high-level mechanics of how a Queue manages its underlying memory array.
In a standard array implementation, both the `front` and `rear` pointers start at `-1`. As you enqueue and dequeue, both pointers strictly move forward (to the right). They never move backward!
Because pointers only move right, if you enqueue 5 items and dequeue 5 items, your pointers are at the end of the array. The queue claims to be "Full", even though indices 0-4 are completely empty!
This massive flaw in Linear Queues is exactly why Circular Queues were invented, allowing pointers to wrap back around to index 0 using the modulo operator.