// ListNode Class Definition #include using namespace std; template class List; template class ListNode { public: ListNode( const Object & theElement = Object(), ListNode * n = NULL ) : element( theElement ), next(n) { } const Object & read() const { return (element); } const ListNode getNext() const { return (next); } private: Object element; ListNode *next; friend class List; }; template class List { public: List() { header = new ListNode; header->element = Object(); header->next = NULL; } bool isempty() const { return (header->next == NULL); } void printList() { ListNode *lptr; lptr = header->next; if (lptr == NULL) cout << "List is empty!\n"; else while (lptr != NULL) { cout << lptr->element << "\n"; lptr = lptr->next; } } void addAtFront(const Object & theElement = Object()) const { ListNode *nptr; nptr = new ListNode; nptr->element = theElement; nptr->next = header->next; header->next = nptr; } private: ListNode *header; }; // Test Program int main() { // Test the ListNode class ListNode node1; cout << node1.read() << " is the value in node1.\n"; ListNode node2(250, &node1); cout << node2.read() << " is the value in node2.\n"; // Test the List class List mylist; if ( mylist.isempty() ) cout << "My list starts out empty.\n"; mylist.printList(); mylist.addAtFront(30); mylist.addAtFront(20); mylist.addAtFront(10); mylist.printList(); cout << "The End\n"; return (0); }