/**插入排序法**/
#include<stdio.h>
#include <string.h>
#include <math.h>
int main()
{
int a[20]={12,15,15,7656,32,3454,43,54,54,234,34,56,5634,7654,34,65,3543,6576,3545,543};//對其排序
int b[20]={0},i,j,k;
b[0]=a[0];
k=0;
for(i=1;i<10;i++)
{
if(a[i]>=b[i-1]) {b[i]=a[i];continue;}
else if(a[i]<b[0])
{
for(j=i-1;j>=0;j--)
{b[j+1]=b[j]; b[0]=a[i];}
continue;
}
else
{
for(j=0;j<i;j++)
{ if(a[i]>=b[j] && a[i]<b[j+1]) {k=j;break;} }
for(j=i;j>k+1;j--)
b[j]=b[j-1];
b[k+1]=a[i];
}
}
for(i=0;i<20;i++)
printf("%d ",a[i]);
printf("\n");
return 0;
}