Code Fragment: LinkedQueue



  // ... (part of class LinkedQueue)
  void enqueue(const Object& e) {		// enqueue element
    NodePtr v = new Node(e, NULL);
    if (sz == 0) head = v;			// if empty, this is new head
    else tail->next = v;			// else link after tail
    tail = v;					// v is now the tail
    sz++;
  }
  Object dequeue() throw(QueueEmptyException) {	// dequeue
    if (isEmpty())
      throw QueueEmptyException("Dequeue of empty queue");
    NodePtr old = head;				// node to remove
    head = head->next;
    if ((--sz) == 0) tail = NULL;		// deletion causes empty queue
    Object result = old->element;
    delete old;
    return result;
  }
  // ...