void append( int value );
int is_present( int value ) const;
int is_empty() const { return head == 0; }
int count() const { return theCount; }
private:
class ListCell
{
public:
ListCell( int value, ListCell *cell = 0):val(value),
next(cell){}
int val;
ListCell *next;
};
ListCell *head;
ListCell *tail;
int theCount;
};
- Write the implementation for the Listclass (nontemplate) version.
- Write the template version of the implementations.
- Declare three list objects: a list of Strings, a list of Cats, and a list of ints.
5.BUG BUSTERS:What is wrong with the following code? (Assume the Listtem-
plate is defined and Catis the class defined earlier in the book.)
ListCat_List;
Cat Felix;
CatList.append( Felix );
cout << “Felix is “
<< ( Cat_List.is_present( Felix ) )? “” : “not “
<< “present” << endl;
Hint(this is tough): What makes Catdifferent from int? - Declare friend operator==for List.
- Implement friend operator==for List.
- Does operator==have the same problem as in Exercise 5?
- Implement a template function for swapthat exchanges two variables.
714 Day 19