// File: list6.h // // Another simple linked list ADT in C++. // This one uses more C++ "features" #ifndef _list6_h #define _list6_h // ***Important: ListItem class is defined in the header file // that is included in "listitem.h" #include "listitem.h" // Each node in the linked list is a ListNode object class ListNode { friend class List ; public: ListItem item ; // data member private: ListNode *next ; // pointer to next node in the linked list ListNode() ; // default constructor ListNode(const ListItem&) ; // alternate constructor ~ListNode() ; // destructor } ; // Position in the linked list is a pointer to the node prior to // the node of interest. typedef ListNode *position ; class List { public: List() ; // default constructor ~List() ; // destructor void Append(const ListItem&) ; // Add item to the end of the list void Prepend(const ListItem&) ; // Add item to the beginning of the list void Delete(position) ; // Remove node at given position int IsMember(const ListItem&) ; // Item on the list? 0=No 1=Yes void Concatenate(List *) ; // Add list to the end of this one List *Duplicate() ; // Return copy of this list void Print() ; // Print the contents of this list int Count() ; // Return number of items in this list // The following 3 functions return copies of the items ListItem *FirstItem() ; // First item on the list ListItem *LastItem() ; // Last item on the list ListItem *ItemAt(position) ; // Return item at given position // See documentation on meaning of position position FirstPos() ; // Position of the first item position NextPos(position) ; // Position after the given one position Locate(const ListItem&) ; // Position of item on list. protected: ListNode header ; int count ; ListNode *last ; } ; #endif