C++ allows a programmer to create templates that can be instantiated. A template allows objects to be created that can store (or use) data of any type.
In this lab you will convert the int linked list class to a template class. Start by downloading the zipfile. It contains:
To convert the class to a template class you must:
void LinkedList::add(int x){ Node *p = new Node(x); // Assign appropriate values to the new node p -> next = head; // Make the head point to the new node head = p; size++; }and the "templated" version
template <typename Type> void LinkedList<Type>::add(Type x){ Node *p = new Node(x); //temporary node // Assign appropriate values to the new node p -> data = x; // Make the head point to the new node head = p; size++; }To use your linked list template class in a program you need to specify what type is to be stored:
Test your linked list template by modifying the driver program in template_test.cpp so that it creates an int linked list and a string linked list, and uses each of the LinkedList methods at least once for each type of list. (Note that the provided version of template_test does not do this for the LinkedList with int hardwired in.)
When you have done this, please show a TA your modified driver program and the results of running it to receive your marks for this lab.