插入法排序
程序员文章站
2024-01-20 21:46:34
...
#include<stdio.h>
#include<stdlib.h>
/* 插入法排序.c */
/* written by Chen Gengru */
/* updated on 2018-11-26 */
int main()
{
int i, j;
int iTemp, iPos;
int a[10];
for (i = 0; i < 10; i++)
{
scanf("%d", &a[i]);
}
for (i = 1; i < 10; i++)
{
iTemp = a[i];
iPos = i-1;
while ((iPos >= 0) && (a[iPos] > iTemp))
{
a[iPos+1] = a[iPos];
iPos--;
}
a[iPos+1] = iTemp;
}
for (i = 0; i < 10; i++)
{
printf("%d\t", a[i]);
}
return 0;
}
上一篇: [asp]怎么添加验证码的解决方法