#include <iostream>
using namespace std;
template<class T>
void InsertionSort(T *src, int size) {
for (int i = 1; i < size; i++) {
T temp = src[i];
int j = i - 1;
while (temp < src[j] && j >= 0) {
src[j + 1] = src[j];
j--;
}
src[j + 1] = temp;
}
}
int main () {
char c_arr[10] = {'a','c','e','h','g','b','i','j','d','f'} ;
InsertionSort(c_arr,sizeof(c_arr) / sizeof(c_arr[0]));
for (int i = 0; i < 10; i++) {
cout << c_arr[i] << " ";
}
cout << endl;
int i_arr[10] = {0,2,3,6,8,9,4,5,7,1};
InsertionSort(i_arr,sizeof(i_arr) / sizeof(i_arr[0]));
for (int i = 0; i < 10; i++) {
cout << i_arr[i] << " ";
}
cout << endl;
return 0;
}
|