编辑代码

#include<iostream>
using namespace std;
template<class T>
void InsertionSort(T *a, int n)
{
int in, out; 
for (out = 1; out < n;out++)  
{
T temp = a[out];  
in = out;
while (in > 0 && a[in - 1] >= temp)  
{
a[in] = a[in - 1];  
in--;
}
a[in] = temp; 
}
}
int main()
{
int a[] = { 11, 9, 20, 7,56, 9,42, 3, 7,15,16 };
cout << "排序前:" << endl;
for (int i = 0; i < 10; i++)
{
cout << a[i] << "  ";
}
cout << endl;
InsertionSort(a, 10);
cout << "排序后:" << endl;
for (int i = 0; i < 10; i++)
{
cout << a[i] << "  ";
}
cout << endl;
system("pause");
return 0;
}