Subclass PQExt of class PQueue
Steps to take:

  1. Determine what the PQueue class is doing. It provides a container for objects of any kind. How are the objects stored? Actually the objects are not stored in the container - only pointers to the objects are stored.

  2. Come up with ideas for determining the maximum object. One idea is to run through all the stored objects, checking the value of each, and output a pointer to the object of highest value. Evaluate this idea: it takes O(n) time. Can this be improved? Consider when the maximum value object changes. Certainly when an object is removed, the maximum value object does not change unless the container becomes empty in which case there is no such object. When an object is inserted, the maximum value object changes if the inserted object has value greater than the current maximum value object. Under no other circumstances does the maximum value object change. These ideas suggest the following solution: maintain a variable, call it themax, which is a pointer to container objects. The value of that variable will be the address of the current maximum value object. When findmax is invoked, the value of themax will be returned - this takes O(1) time which is much faster than the first idea. The only question is how to update themax according to the discussion earlier.

    Here are some ideas. On a call to remove, themax can be set to NULL if the container is empty. On a call to insert(theobject), themax should be set to point to theobject if the value of themax's object is less than the value of theobject's object. Actually it is unnecessary to modify remove - just add a test for an empty container in insert - if the container is empty then certainly theobject will be the new themax.

  3. Write code.