用c语言实现插入排序

来源:互联网 发布:怎么查看淘宝信誉积分 编辑:程序博客网 时间:2024/05/21 23:00


//insert_sort: the first example in the <introduction to algorithms> in chapter2
#define N 10
#include<stdio.h>
int main()
{
int key,j;
int a[N]={6,1,8,5,3,7,9,4,2,0};
for(int i=1;i<N;i++)
{
key=a[i];
j=i-1;
while(a[j]>key&&j>=0)
{
a[j+1]=a[j];
j--;
}
a[j+1]=key;
}
for(int i=0;i<N;i++)
{
printf("%d\t",a[i]);
}
return 0;
}
原创粉丝点击