/* A class representing a forward-linked list of strings. This code contains * several serious errors, so don't use it as a reference! */ class ForwardList { public: /** * Constructor: ForwardList(numElems, defaultValue) * Usage: ForwardList myList(10); // Contains ten copies of the empty string * Usage: ForwardList myList(10, "Hello!"); // Contains ten copies of "Hello!" * ------------------------------------------------------------------- * Constructs a new list of the specified size where each element is * initialized to the specified value. If no size is specified, defaults to * zero. If no default value is specified, the empty string is used. */ ForwardList(int numElems = 0, string defaultValue = ""); /** * Constructor: ForwardList(vector::iterator begin, * vector::iterator end); * Usage: ForwardList myList(v.begin(), v.end()); * --------------------------------------------------------------------- * Constructs a new list whose elements are equal to those specified by * the input pair of vector::iterators. */ ForwardList(vector::iterator begin, vector::iterator end); /** * Destructor: ~ForwardList(); * Usage: delete myListPtr; * --------------------------------------------------------------------- * Cleans up any memory allocated by this ForwardList object. */ ~ForwardList(); /** * Type: iterator * --------------------------------------------------------------------- * A forward iterator that can read and write values stored in the * ForwardList. */ typedef something-implementation-specific iterator; /** * Functions begin() and end() * Usage: for(ForwardList::iterator itr = l.begin(); itr != l.end(); ++itr) * ---------------------------------------------------------------------- * Returns iterators to the first element in the list and the first element * past the end of the list, respectively. */ iterator begin(); iterator end(); /** * Functions: push_front(val), pop_front(), front() * Usage: v.push_front("This is a string!"); s = v.front(); v.pop_front(); * ---------------------------------------------------------------------- * push_front prepends the specified element to the linked list, * increasing its size by one. pop_front removes the first element of the * list without returning its value; use front() before calling pop_front() * if you want to retrieve the value. * * front() returns a reference to the first element in the list, so it's * legal to write either val = front() or front() = val. */ void push_front(string value); void pop_front(); string& front(); /** * Functions: empty(), size() * Usage: if(v.empty()) ... if(v.size() > 10) ... * ----------------------------------------------------------------------- * empty() returns whether the list is empty (i.e. begin() == end()). * size() returns the number of elements stored in the list. */ bool empty(); int size(); private: /* ... implementation details ... */ };