Program defines the BinaryHeap class constructor. The constructor takes a single argument of type unsigned int which specifies the maximum capacity of the binary heap. The argument passed on to the constructor for the array member variable. Notice too that the array is initialized so that its positions are numbered starting from subscript 1 rather than the default of zero.
Program: BinaryHeap Class Constructor, Destructor and Purge Member Function Definitions
The purpose of the Purge member function of the BinaryHeap class is to delete from the priority queue all contained and owned objects. Pointers to the contained objects are found in the first array positions. Clearly the worst-case running time for the Purge function is
where is the worst-case time required to delete an object instance.
The implementation of the destructor for the BinaryHeap class is trivial as it simply calls Purge to do its work. Consequently, the destructor has the same running time as above.