Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

6.5 Sequenceable Classes

Classes Dlist, Slist, and Queue implement the Sequence interface. This interface, which extends the Collection interface, contains methods for collections in which the order of elements can be determined externally by the client of the collection, and elements can be accessed by index.

6.5.1 Dlist

Class Dlist implements a doubly-linked list of elements ordered externally by the client of the class. Duplicate entries are allowed.

Items can be inserted efficiently at the beginning, end, or middle of the list, and can be removed the same way. There are several ways to retrieve elements from within the collection. One is by numeric index. Another is by searching for an element that is equal to a given item, as determined by the equals() method inherited or overridden from class Object. Finally, you can search for an element which is identical to a given item, that is, equal in the sense of the == operator.

The primary difference between Dlist and Slist, described below, is that a Dlist provides an enumerator that allows for movement both forward and backward within the collection. The cost is that each node in the Dlist contains one more pointer than an Slist. The storage and maintenance of this extra pointer means that Slists are slightly more efficient in space and time.

The following example, given in its entirety in DlistExample.java, uses a Dlist to determine whether a word or sentence is a palindrome or not.


NOTE: Complete code for this exampleis located in the examples directory created for your installation of Tools.h++ Professional. The "Examples" chapter in Part V, "Resources," describes the location of that directory, or you can check the online build guide for your installation media.

In testing whether a string is a palindrome or not, this program does not consider white-space and punctuation. In fact, anything other than letters and digits are not considered.

For example:

6.5.2 Slist

Class Slist implements a singly-linked list of elements ordered externally by the client of the class. Duplicate entries are allowed.

Items can be inserted efficiently at the beginning, end, or middle of the list, and can be removed in the same way. There are several ways to retrieve elements from within the collection. One is by numeric index. Another is by searching for an element that is equal to a given item, as determined by the equals() method inherited or overridden from class Object. Finally, you can search for an element which is identical to a given item; that is, equal in the sense of the == operator.

See the entry for Dlist above for a discussion of the difference between classes Dlist and Slist.

6.5.3 Queue

Class Queue implements a First-In-First-Out (FIFO) queue of objects. A Queue is a sequential list for which all insertions are made at one end via put(), but all removals are made from the other end via get(). Duplicate entries are allowed.

Note that this class extends Slist and that you can use inherited methods such as isEmpty() and size().


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.