#include<stdio.h>
void Insertsort(int n[], int x)
{
int i,end,temp;
for (i = 0; i < x-1; i++)
{
end = i;
temp = n[i + 1];
while (end>=0)
{
if (temp <= n[end])
{
n[end + 1] = n[end]; //后移
}
else {
break;
}
end--;
}
n[end + 1] = temp;
}
}
int main()
{
int i,n[10] = { 1,7,3,9,2,4,0,5,8,6 };
Insertsort(n, 10);
for (i = 0; i < 10; i++)
{
printf("%d ", n[i]);
}
return 0;
}
(自用)插入排序
于 2024-03-20 19:55:35 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)