#include<iostream>
using namespace std;
void print(int a[], int n)
{
for(int j= 0; j<n; j++)
{
cout<<a[j] <<" ";
}
cout<<endl;
}
void insertSort(int a[], int n)
{
for(int i = 1; i < n; i++)
{
if(a[i] < a[i-1])
{
int j = i-1;
int x = a[i];
while(j >= 0 && x < a[j])
{
a[j+1] = a[j];
j--;
}
a[j+1] = x;
}
}
}
int main()
{
int a[11] = {11, 9, 20, 7,56, 9,42, 3, 7,15,16};
cout<<"初始序列:";
print(a,11);
insertSort(a,11);
cout<<"排序结果:";
print(a,10);
system("pause");
}