#ifndef _DLLIST_H_ #define _DLLIST_H_ template class dList; // Forward reference to a dList template class dlNode { friend class dList; // dList should be able to use and inspect // dList_node's protected members and methods protected: dlNode(); dlNode(Object val); ~dlNode(); Object value; dlNode *flink; // pointer to the next node in the list dlNode *blink; // pointer to the previous node in the list }; template class dList { public: dList(); // initializes the dList dList(Object default_value); // initializes the dList ~dList(); // destroys the dList's nodes void insertBeforeCursor(Object value); // inserts the value before the node // pointed to by the list cursor void insertAfterCursor(Object value); // inserts the value after the node // pointed to by the list cursor void append(Object value); // appends the value to the end of the list void prepend(Object value); // appends the value to the front of the list void next(); // moves the list cursor to the next // element in the list void prev(); // moves the list cursor to the previous // element in the list bool endOfList(); // true if the list cursor points to the // sentinel node; false otherwise // If the list is empty, the following two operations make the // list cursor point to the list's sentinel node void first(); // resets the list cursor to the first // element in the list. void last(); // resets the list cursor to the last // element in the list Object get(); // returns the value of the node pointed to // by the list cursor void set(Object val); // sets the current node to the indicated value void deleteNode(); // deletes the node pointed to by the list cursor // and advances the list cursor to the next // list element bool isEmpty(); // returns whether the list is empty // set the value in the sentinel node void setSentinelValue(Object value) { sentinel_node->value = value; } protected: dlNode *cursor; // the list cursor dlNode *sentinel_node; // a pointer to the sentinel node }; /* Traverse, where list is a (dList *) */ #define dl_traverse(list) \ for((list)->first(); !(list)->endOfList(); (list)->next()) #define dl_rtraverse(list) \ for((list)->last(); !(list)->endOfList(); (list)->prev()) #include "dList.cpp" #endif