1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <iostream> using namespace std; template <class T> void swap_these(T & a, T & b) { T a_old = a; a = b; b = a_old; } int main() { int array[5] ={1,2,3,5,4}; swap_these(array[3], array[4]); for(int i=0;i<5;i++) { cout << array[i] << endl; } return 0; } |