using namespace std; #include /* define lists with arbitrary type as parameter */ template class List { private: T element; List *next; public: List (T head, List *tail) { element = head; next = tail; } ; T head() { return element; }; List *tail(){ return next; }; }; // /* define constructor: the cons-function */ // /* template */ // /* List::List(T head, List *tail) { */ // /* }; */ // /* define head-function */ // template // T List::head () { // return element; // }; // /* define tail-function */ // template // List *List::tail () { // return next; // }; int main () { List *intlist; /* list of integers */ List * stringlist; /* list of strings */ /* create a two-element list of integers and a two-element list of strings */ intlist = new List (4, NULL); stringlist = new List ("This is a string", NULL); intlist = new List (5, intlist); stringlist = new List ("This is another string", stringlist); /* print the elements of the integer list */ while (intlist != NULL) { cout << "The next element of the integer list is " << intlist->head() << "\n"; intlist = intlist->tail(); } /* print the elements of the string list */ while (stringlist != NULL) { cout << "The next element of the stringlist list is " << stringlist->head() << "\n"; stringlist = stringlist->tail(); } return 0; }