正文

直接插入排序(C语言)2005-11-19 11:13:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/chaoyun2004/7147.html

分享到:

#include"stdio.h"#include"conio.h"void insertSort(int a[],int count)   /*count为排序数字个数*/{   int i,j,temp;   for(i=1;i<count;i++)    /*依次插入数字到它前面已经排好序的数字中去*/   {      temp=a[i];      j=i-1;      while(a[j]>temp && j>=0)      {        a[j+1]=a[j];         j--;      }      if(j!=(i-1)) /*第i个数字比前面的都大,不需要重新插入*/             {        a[j+1]=temp;      }             }}void main(){   int a[7]={8,10,2,3,1,7,13};   int i;   insertSort(a,7);   clrscr();   for(i=0;i<7;i++)      /*输出排序后的结果*/   {      printf("%4d",a[i]);   }}

阅读(11120) | 评论(5)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册