Code Fragment: SSPQ2



  // ... (continuation of SortedSeqPriorityQueue)
  void insertItem(const Key& k, const Element& e) {	// insert into queue
    if (S.isEmpty())
      S.insertFirst(Item(k, e));			// if empty insert first
    else if (comp(k, key(S.last())) > 0)		// greater than last?
      S.insertAfter(S.last(), Item(k,e));		// insert at end
    else {
      Position curr = S.first();			// start search
      while (comp(k, key(curr)) > 0)			// skip over small keys
        curr = S.after(curr);
      S.insertBefore(curr, Item(k,e));			// insert here
    }
  }
  Element& minElement()					// element with min key
      throw(EmptyContainerException) {
    if (S.isEmpty())
      throw EmptyContainerException("Minimum element of empty queue");
    else
      return element(S.first());
  }
  const Key& minKey() const     			// returns minimum key
      throw(EmptyContainerException) {
    if (S.isEmpty())
      throw EmptyContainerException("Minimum key of empty queue");
    else
      return key(S.first());
  }
  void removeMin()					// remove minimum
      throw(EmptyContainerException) {
    if (S.isEmpty())
      throw EmptyContainerException("Removal from empty queue");
    S.remove(S.first());
  }
};