Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Constructor, Destructor and Purge Member Functions

Program gif 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.

   program24875
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 tex2html_wrap_inline61308 array positions. Clearly the worst-case running time for the Purge function is

displaymath66376

where tex2html_wrap_inline66380 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.


next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.