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

Implementation

Program gif declares the TwoWayMergeSorter<T> class template. A single member variable, tempArray, is declared. This variable is a pointer to an Array<T> instance. Since merge operations cannot be done in place, a second, temporary array is needed. The tempArray variable is keeps track of that array. The TwoWayMergeSorter constructor simply sets the tempArray pointer to zero.

   program44548
Program: TwoWayMergeSorter<T> Class Definition

In addition to the constructor, three protected member functions are declared, Merge and two versions of DoSort. The purpose of the Merge function is to merge sorted subsequences of the array to be sorted. The two DoSort routines implement the sorting algorithm itself.


next up previous contents index

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