// LinkedListOne.h // revised 10 sep 04 tom bailey // printed the list elements; add op<< for standard C++ printing // revised 23 feb 04 tom bailey // The methods are insert and remove from the front, return // whether empty, and write the list elements. // tom bailey 18 sep 02 // Declare a LinkedList class. #pragma once #include using std::ostream; #include "node.h" class LinkedList { public: // Post: this LinkedList is an empty NULL-terminated // linked list. LinkedList(); // Post: all the Nodes of this LinkedList have // been deallocated. This LinkedList is // an empty NULL-terminated linked list. ~LinkedList(); // Post: x has been added to the beginning of this // LinkedList. void insertAsFirst( double x ); // Pre: this LinkedList is not empty; // Post: the entry in the first node of this LinkedList // has been returned. The first node has been // removed from this LinkedList. double removeFirst(); // Post: if this LinkedList is empty, true has been // returned; otherwise, false has been // returned. bool empty() const; // Post: the values in this LinkedList have been // written to outfile. void print( ostream & outfile ) const; // Helper methods // The helper methods accept a pointer to the rest of // the list in place of the calling instance pointer, // this. In the helper methods, all the pointers, // both start in LinkedList and link in Node, can be // treated in the same way. // The helper methods are static, they do not have a // calling instance. protected: // Pre: ptr points to a NULL-terminated linked // list. // Post: x has been added to the beginning of // the list. static void insertAsFirst( Node * & ptr, double x ); // Pre: ptr points to a non-empty NULL-terminated // linked list. // Post: the first element of the list has been // removed. static double removeFirst( Node * & ptr ); // Data members protected: // Since start is protected, client code has no // access to the data stored in this LinkedList, // even though struct Node is very public. Node * start; }; // Post: list has been written to outfile ostream & operator<< ( ostream & outfile, const LinkedList &list);