#include using std::cout; using std::endl; template void swap(T& x, T& y) { T temp; temp = x; x = y; y = temp; } void swap(char*& x, char*& y) { char* temp; temp = new char[strlen(x) + 1]; strcpy(temp, x); delete []x; x = new char[strlen(y) + 1]; strcpy(x, y); delete []y; y = temp; temp = NULL; } void main() { //call to swap with ints int x = 3; int y = 6; swap(x, y); cout << x; cout << y; cout << endl; //call to swap with doubles double j = 7.12111; double k = 8.99889; swap (j,k); cout << j; cout << k; cout << endl; //call to swap with chars char c1 = 'a'; char c2 = 'b'; swap (c1,c2); cout << c1; cout << c2; cout << endl; //call to swap with character strings char *a1 = new char[7]; strcpy(a1,"orange"); char *a2 = new char[6]; strcpy(a2, "apple"); swap (a1,a2); cout << a1 << endl; cout << a2 << endl; }