Code Fragment: SSPQL1



template <typename Key, typename Element, typename Comp>
class SortedSeqPriorityQueueLoc { 
protected: 						// typename shortcuts
  struct  LocItem;					// a locatable item
  typedef LocItem*			 LocItemPtr;	// a pointer to LocItem
  typedef NodeSequence<LocItemPtr>	 Sequence;	// sequence
  typedef Sequence::Position 		 Position;	// position in sequence
  // ... (insert LocItem here)
public:
  // ... (insert Locator here)
protected: 						// local utilities
  const Key& key(const Position& p) const 		// position's key
    { return p.element()->key(); }
  Element& element(const Position& p)			// position's element
    { return p.element()->element(); }
  void locInsert(LocItemPtr locItem);			// insert utility
private: 						// member data
  Sequence   S;						// sorted sequence
  Comp       comp;					// comparator
public: 						// public functions
  SortedSeqPriorityQueueLoc() : S(), comp() { }		// constructor
  Locator min() const 					// minimum item
      throw(EmptyContainerException) {
    if (S.isEmpty()) throw EmptyContainerException("Min of empty queue");
    else
      return Locator(S.first().element());
  }
  Locator insertItem(const Key& k, const Element& e) {	// insert (key,element)
    LocItemPtr locItem = new LocItem(k, e);		// allocate new item
    locInsert(locItem);					// insert it
    return Locator(locItem);				// return its locator
  }
  void remove(Locator& loc)				// remove item
      throw(InvalidPositionException) {
    if (loc.isNull()) throw InvalidPositionException("Removal of null locator");
    S.remove(loc.locItem->pos);				// remove from sequence
    delete loc.locItem;					// delete the item
    loc.locItem = NULL;					// invalidate pointer
  }
  // ...