/* set.cpp should contain the definition and implementation of the Set class. Set should be a templated class that can hold any type of data. It should hold the data in an array with a template type (you will also need a way to resize this array if it becomes full). It should contain functions for adding an element in sorted order, printing all set elements, and finding the union and intersection between this set and another set. The union and intersection functions should return a new Set object (or reference) that is the result of the operation. Set should also have a constructor to initialize space for the array, and a destructor to release the space. You should model the Set class after the templated Vector class we wrote in lab. Also, recall from lab that malloc and free do not work with templated classes. Instead, use C++-style array allocation. For example: int *arr = new int[10]; delete[] arr; #include #include using namespace std;*/ template class Set { private: T *arr; int length; int pos; public: Set(void); ~Set(void); void addVal(T); void printVec(void); void insertSort(void); int getLength(void); int getPos(void); }; template Set ::Set(void) { length = 50; pos = 0; arr = new T[length]; } template Set ::~Set(void) { delete [] arr; } template void Set::addVal(T value) { int i; T *temp; T tval; //Resize as needed if(pos == length-1){ temp = new T[length+10]; for(i=0; i void Set::insertSort(void){ int i, j; T index; for (i=0; i < pos; i++){ index = arr[i]; j = i; while ((j > 0) && (arr[j-1] > index)){ arr[j] = arr[j-1]; j = j - 1; } arr[j] = index; } } template void Set::printVec(void){ int i; if(pos < 0){ cout << "There are no values in Vector!" << endl; }else{ for(i=0; i <= pos; i++){ cout << arr[i] << " "; } cout << endl; } } template int Set :: getLength(void){return length;} template int Set :: getPos(void){return pos;}