正文

选择排序法2005-04-12 11:37:00

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

分享到:

#include<stdio.h> #include<math.h> #define wap(x,y,t) ((t)=(x),(x)=(y),(y)=(t)) #define max 12 void sort(int a[],int x); main() { int a[max],i,j; clrscr(); printf("how many elems do you want to compare?number(<=12):\n"); scanf("%d",&i); while(i>12||i<=0) { printf("error due to the wrong input,please input it again!\n"); scanf("%d",&i); } printf("\nplease enter the numbers:\n"); for(j=0;j<i;j++) { fflush(stdin);   scanf("%d",&a[j]);   } printf("\nthe original numbers is:\n"); for(j=0;j<i;j++) { printf("%d",a[j]); printf("/t/t"); } printf("/n"); sort(a,i); } void sort(int a[],int x) { int i,j,maxsu,k,m,temp; for(i=0;i<(x-1);i++) {   maxsu=a[i];   for(j=i;j<x;j++)   {     if(a[j]<maxsu)      {      maxsu=a[j];      k=j;     } } wap(a[i],a[k],temp); } printf("the sort number is:\n"); for(m=0;m<x;m++) { printf("%d",a[m]); printf("/t/t"); } }

阅读(4358) | 评论(0)


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

评论

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