/* * Program to demonstrate pointer based linked lists. */ /* * @class List * ADT list - Pointer-based implementation. */ class List { public: // Constructors and destructor: List(); // Default constructor List(const List& aList); // Copy constructor. Pass list to copy. ~List(); // Destructor // List operations: bool isEmpty() const; // 'const' signifies that this function can not // modify any class data members (unless member is // declared 'mutable'. int getLength() const; void insert(int index, const int& newItem); // 'newItem' cannot be updated. 'int&' --> // reference var, cannot refer to another // object. void remove(int index); void retrieve(int index, int& dataItem) const; private: /** A node on the list. */ struct ListNode { int item; ListNode *next; // Pointer to next node. }; int size; // Number of items in list ListNode *head; // Pointer to linked list of items /** Locates a specified node in a linked list. * @pre index is the number of the desired node. * @post None. * @param index The index of the node to locate. * @return A pointer to the index-th node. If index < 1 * or index > the number of nodes in the list, * returns NULL. */ ListNode *find(int index) const; };