Description
设计一个程序,实现直接插入排序算法,并输出{9,8,7,6,5,4,3,2,1,0}的排序过程。
Input
Output
每个排序过程输出一行,直到排序完成。
Sample Output
9 8 7 6 5 4 3 2 1 0
8 9 7 6 5 4 3 2 1 0
...
...
/*烟台大学计算机与控制工程学院 2016 作者: 马春澎 题目名称:oj 3044 直接插入排序 完成日期:2017年3月30日 */ #include<stdio.h> int main() { int a[10]= {9,8,7,6,5,4,3,2,1,0}; int i,j,k,temp; for(i=1; i<10; i++) { if(a[i]<a[i-1]) { temp=a[i]; for(j=i-1; j>=0 && a[j]>temp; j--) { a[j+1]=a[j]; } a[j+1]=temp; } for(k=0; k<9; k++) printf("%d ",a[k]); printf("%d\n",a[9]); } return 0; }

本文介绍了一种直接插入排序算法的实现方式,并通过一个具体的排序示例展示了整个排序过程。文章提供了一个C语言程序,该程序能够对数组{9,8,7,6,5,4,3,2,1,0}
2787

被折叠的 条评论
为什么被折叠?



