[ RCOS.java Home | RCOS Home | David's Home ]

List CRC

Name:

ListHeader

Comment:

The following class defines a "list" -- a singly linked list of list elements, each of which points to a single item on the list.

By using the "Sorted" functions, the list can be kept in sorted in increasing order by "key" in ListElement.

Collaborators:

Responsibilities:

class List {
  public:
    List();                     // initialize the list
    ~List();                    // de-allocate the list

    void Prepend(void *item);   // Put item at the beginning of the list
    void Append(void *item);    // Put item at the end of the list
    void *Remove();             // Take item off the front of the list

    void Mapcar(VoidFunctionPtr func);  // Apply "func" to every element
                                        // on the list
    bool IsEmpty();             // is the list empty?


    // Routines to put/get items on/off list in order (sorted by key)
    void SortedInsert(void *item, int sortKey); // Put item into list
    void *SortedRemove(int *keyPtr);            // Remove first item from list

  private:
    ListElement *first;         // Head of the list, NULL if list is empty
    ListElement *last;          // Last element of list
};