直接插入排序
#include<iostream.h>
void InsertSort(int A[],int n)
{
int x;
int i,j;
for(i=1;i<n;i++)
{
x=A[i];
for(j=i-1;j>=0;j--)
if(x<A[j])
A[j+1]=A[j];
else
break;
A[j+1]=x;
}
}
void main()
{
int a[]={12,32,14,25,98,24,44};
InsertSort(a,7);
for(int i=0;i<7;i++)
cout<<a[i]<<" ";
cout<<endl;
}
浙公网安备 33010602011771号