#ifndef _TPQUEUE_H #define _TPQUEUE_H // templated priority queue class // written and modified thousands of times // the last time was 11/27/95 for cps 100, fall 1995 // to use vector class rather than array type // // operations: // // PQueue(int) // construct pqueue of specified size // // void Insert(const Kind &, int) // insert Kind object with specified // integer priority // // int NumElts() const // returns the number of elements in the priority queue // // bool IsEmpty() const // returns true if pqueue is empty, otherwise returns false // // void DeleteMin() // remove minimal element from queue // // void MinElt(Kind &, int &) // return minimal element and its integer priority // // Complexity: // // a heap-based implementation is used, so MinElt is O(1) // and Insert/DeleteMin are O(log n) where n is # of items in pqueue #include "vector.h" template class PQueue { public: PQueue(int); // initialize to given size ~PQueue(); void Insert(const Kind &,int); // insert kind with int priority int NumElts() const; // return # of elements in queue bool IsEmpty() const; // return true iff empty void DeleteMin(); // remove min elt from pqueue void MinElt(Kind &,int &); // return min elt and priority private: struct Qelt { Kind thing; // item stored in pqueue int priority; // priority of the item }; void Heapify(int vroot); // percolate down function Vector myList; // array of prioritized stuff int myNumElts; // # elements in priority queue }; // uncomment line below if including source code (no template.cc) // #include "tpqueue.cc" #endif