// File HList.h // // A heterogeneous linked list. // Modified from Lab 6. // #ifndef HLIST_H #define HLIST_H #include using namespace std; class HList ; // The node used in HList // This is a abstract class with pure virtual functions class HNode { friend class HList ; public: HNode() ; virtual ~HNode() ; // virtual destructor! virtual void print(ostream& os = cout) const ; virtual HNode *clone() const ; virtual bool operator==(const HNode& rhs_ref) const ; // tricky! bool operator!=(const HNode& rhs_ref) const ; // not virtual protected : HNode *next; }; // List is a linked list of ints class HList { public: // Creates a default empty list HList(); // Creates a copy of another list HList(const HList& L); // Destructor ~HList(); // Assignment operator const HList& operator=(const HList& rhs); // Deletes all the elements in the list void clear(); // Insert Node at the front or back void push_front(HNode *ptr) ; void push_back(HNode *ptr) ; // Return pointer to first node. // Returns NULL if list is empty HNode *front() ; // Return pointer to last node. // Returns NULL if list is empty HNode *back() ; // Remove first node, no return value void pop_front() ; // Find node with "value" equal to given one HNode *find(const HNode& X) const ; // Remove first node with "value" equal to X // return success or failure bool remove(const HNode& X) ; // Prints the list void print(ostream& os =cout) const; // Returns the size of the list unsigned int size() const; protected: HNode header ; // not pointer! HNode *tail_ptr ; unsigned int m_size ; private: // Housekeeping functions // make a copy, used by copy constructor and assignment void duplicate(const HList& L) ; }; // Overloaded output operator prototype ostream& operator<< (ostream& os, const HList& L) ; #endif