Data Structures · Queue ADT

A queue built from a linked list

Enqueue and dequeue values and watch the C++ run one line at a time. Each value lives in its own Node on the heap. Items leave at head, the front of the queue, and join at tail, the rear. Keeping a tail pointer is what makes enqueue fast: the code never has to walk the list to find the end.

Heap: the nodes, from head (front) to tail (rear)

Variables

What is happening

ReadyType a number and press enqueue(x).

Calls from main()

    LinkedQueue.cpp

      Compare this with the linked-list stack: dequeue is the same as the stack's pop. Only enqueue differs, because new items go on the tail end instead of the head.