Creating a Header Class

Although you can use a class module to emulate the elements of a dynamic data structure, as shown in the previous section, you’ll need a different class module to “anchor” the data structure. This class module will generally have only a single instance per data structure and will contain pointers to the beginning, and perhaps the end, of the data structure. In addition, this class often contains the code necessary to add and delete items in the list.

Generally, the header class contains one or more references to objects of the type used in building the data structure, and perhaps other information about the structure itself. For example, a hypothetical class named ListHeader with the following information has a reference to the first item in a list and the last item in the list:

Dim liFirst As ListItem
Dim liLast As ListItem

Note that the class doesn’t contain a self-referential data element. There’s generally no reason for a list header to refer to another list header, so this example doesn’t contain a reference to anything but the list items. In addition, the header class need contain nothing more than a reference to the first item in the data structure. It just depends on the functionality your data structure needs.

How you work with the items in the data structure–adding, deleting, and manipulating them–depends on the logical properties of the data structure you’re creating. Later in this chapter, you’ll find example data structures that emulate stacks and queues, each of which has its own ideas about adding and deleting items.

© 1997 by SYBEX Inc. All rights reserved.