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

Constructor and Purge Methods

Program gif defines the BinaryHeap constructor. The constructor takes a single argument of type int which specifies the maximum capacity of the binary heap. The constructor allocates an array of the specified size plus one. This is done because array position zero will not be used. The running time of the constructor is O(n), where n is the maximum length of the priority queue.

   program24246
Program: BinaryHeap class constructor and Purge methods.

The purpose of the Purge method is to make the priority queue empty. The Purge method assigns the value null to the array positions one-by-one. Clearly the worst-case running time for the Purge method is O(n), where n is the maximum length of the priority queue.


next up previous contents index

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