// List.h - interface file for linked list List ADT #if !defined(LINKEDLIST) #define LINKEDLIST #include using namespace std; typedef int ElementType; class List { private: class Node { public: //------ Node operations Node() : next(0) { } Node(ElementType dataValue) : data(dataValue), next(0) { } //------ Node data members ElementType data; Node * next; }; typedef Node * NodePointer; public: List(); List(const List & origList); ~List(); const List & operator=(const List & rightSide); bool empty() const; void insert(ElementType dataVal, int index); void erase(int index); ElementType at( int index ) const; int search(ElementType dataVal); /*-------------------------------------------------------------------- Search for a data value in this list. Precondition: None Postcondition: Index of node containing dataVal is returned if such a node is found (first node index = 0, etc.), -1 if not. --------------------------------------------------------------------*/ void display(ostream & out) const; /*-------------------------------------------------------------------- Display the contents of this list. Precondition: ostream out is open Postcondition: Elements of this list have been output to out. --------------------------------------------------------------------*/ int nodeCount(); /*-------------------------------------------------------------------- Count the elements of this list. Precondition: None Postcondition: Number of elements in this list is returned. --------------------------------------------------------------------*/ void reverse(); /*-------------------------------------------------------------------- Reverse this list. Precondition: None Postcondition: Elements in this list have been reversed. --------------------------------------------------------------------*/ bool ascendingOrder(); /*-------------------------------------------------------------------- Check if the elements of this list are in ascending order. Precondition: None Postcondition: true is returned if the list elements are in ascending order, false if not. --------------------------------------------------------------------*/ private: NodePointer first, last; int mySize; }; ostream & operator<<(ostream & out, const List & aList); /*-------------------------------------------------------------------- Write data from each node of this list to output stream out. Precondition: Output stream out is open Postcondition: Elements of this list have been output to out, and the output stream out is returned. --------------------------------------------------------------------*/ #endif