// // // dlist.h // Data structure to manage doubly linked lists of integers. // #ifndef DLIST_H #define DLIST_H // The links and values are declared locally in dlist.cc and are used // only within Dlist. // class Dlink; class Dlist { public: Dlist(); // Construct a new empty list. ~Dlist(); // Destructor for the list. It deallocates the list, and all items on list int First() const; // Returns the first value in the list. int Last() const; // Returns the last value in the list. void Prepend(int value); // Adds value to beginning of list. void Append(int value); // Adds value to end of list bool InsertAfter(int newValue, int existingValue); // Adds newValue after the first occurrence of existingValue in // the list. Returns false if existingValue is not in the list. // Otherwise it returns true. bool Remove(int value); // Removes value from the list. Returns false if value is not in // the list. Otherwise it returns true. void Clear (); // Removes all the elements from the list. Frees the memory used // by each cell, but does not free the list itself. void Sort(); // Sorts the list. void Print() const; // Prints the contents of the list to standard output. void SelfTest(int start); // Tests the list. Start is the first value inserted in the list. private: Dlink *first; // Head of the list. NULL if list is empty Dlink *last; // Last element of list. NULL if list is empty. Dlink *Find ( int value ); // Return the cell in the list that contains value. Return NULL // if value is not found. void Sort(Dlink *first, Dlink *last); // Internal Sort routine to sort a portion of the list. Dlink* Partition(Dlink *first, Dlink *last); // Internal routine used to partition the list for sorting using // the quicksort algorithm. }; #endif // DLIST_H