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

Representing Partitions

Program gif declares the abstract class Partition. Since a partition is a set of sets, it makes sense to use a class derived from the abstract base class Set defined in Section gif. The two member functions, Find and Join, correspond to the partition operations described above.

   program28678
Program: Partition Class Definition

The elements of a partition are also sets. Consequently, the objects contained in a Partition are also derived from the Set class. The Find member function of the Partition class expects as its argument a reference to a Set::Element and returns a reference to the Set which contains the specified element.

The Join member function takes two arguments, both of them references to Set instances. The two arguments are expected to be distinct elements of the partition. The effect of the Join operation is to remove the specified sets from the partition and replace them with a Set which represents the union of the two.


next up previous contents index

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