Two Pointers
You maintain `front` pointing to the head of the list, and `rear` pointing to the tail. Both start as `NULL`.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Implementing a Queue with a Linked List solves the "False Overflow" and fixed-size limitations of Array Queues. It grows dynamically as needed.
You maintain `front` pointing to the head of the list, and `rear` pointing to the tail. Both start as `NULL`.
Always add to the `rear` (tail). `rear.next = new Node`, then `rear = new Node`. If the queue is empty, both pointers point to the new node.
Always remove from the `front` (head). Save the value, then `front = front.next`. If `front` becomes `NULL` after popping, remember to set `rear = NULL` too!