编辑代码

#include<iostream>
using namespace std;
bool insertSort(int a[], size_t L)
{
	int i,j=1;
    bool f=0;
	for(int N=1; N<L; ++N)
	{
		int v=a[N];
		int M=N-1;
		for(;M>=0;--M)
		{
			if(v<a[M])
			{
				a[M+1]=a[M];
				f=1;
			}
			else
			{
				break;
			}
		}
		a[M+1]=v;
		if(f)
		{
			cout<<"第"<<j<< "轮排序结果为:"<<endl; 
			for(i=0;i<L;i++)
			{
			cout<<"  "<<a[i];
			}
			j++;
			cout<<endl;
			f=0;
		}
	}
	return 1;
}
int main()
{
	int i;
	int a[]={11, 9, 20, 7, 56, 9, 42, 3, 7, 15, 16};
	int L=sizeof(a)/sizeof(int);
	insertSort(a,L);
	cout<<"最终的排序结果为:"<<endl;
	for(i=0;i<L;i++)
	{
	cout<<"  "<<a[i];
	}
	return 0;
}