[prev] 78 [next]
Use pointers to both ends

[Diagram:Pic/linkedListQueue.png]

Dequeue from the front …

dequeue(Q):
|  Input  non-empty queue Q
|  Output front element d, dequeued from Q
|
|  d=Q.front.value        // first element in the list
|  Q.front=Q.front.next   // move to second element
|  return d

Enqueue at the rear …

enqueue(Q,d):
|  Input queue Q
|
|  new=makeNode(d)     // create new list element      
|  Q.rear.next=new     // add to end of list
|  Q.rear=new          // link to new end of list