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

Implementation

A binary heap is a heap-ordered complete binary tree which is implemented using an array. In a heap the smallest key is found at the root and since the root is always found in the first position of the array, finding the smallest key is a trivial operation in a binary heap.

Program gif declares the class BinaryHeap. The BinaryHeap class is derived from the PriorityQueue abstract base class. Since BinaryHeap is a concrete class it provides implementations for all of the member functions declared as pure virtual functions in the base class. In the interest of brevity, the declarations of these functions have been elided from Program gif.

   program24847
Program: BinaryHeap Class Definition




next up previous contents index

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