为编程爱好者分享易语言教程源码的资源网

网站首页 > 易语言相关 > 易语言例程 正文

最快的排序算法_桶排序源码

三叶资源网 2018-11-21 16:19:43 易语言例程 1992 ℃ 1 评论

最快的排序算法_桶排序

最快的排序算法 

[ 江南孤峰 发表于 2006-11-9 12:57:00 ] 

  

/****************************************************************\

 最快的排序算法:   桶 排 序                          

 经分析通过比较的排序算法如,选择排序,插入排序,快速排序,堆排序 

 等最快为 n*log(n),这是比较排序算法的极限任何通过比较进行排序 

 的算法都不可能超过这个极限. 现在要介绍的 桶排序 可以超过它为 

 n ,当然 桶排序 的灵活性却拿不出手,必须要知道待排序数组中最大 

 的数.下面的程序,首先由用户输入数组的大小,程序随机产生最大数为

 不超过 10000 的随机数组,最后输出原始数组,以及排序后的数组.   

      #########################################

         独学而无友,则孤陋而寡闻  

         诚交天下程序员  !  

         Q 群: 28011342  

      #########################################

                                                             

 编译器: VC ++ 6.0  Author : 江南孤峰   Time :2006--10--27 

\****************************************************************/ 


#i nclude <stdio.h>

#i nclude <malloc.h>

#i nclude <memory.h>

#i nclude <stdlib.h>

#i nclude <ctype.h>


int main(){

 int order[10000],total,*array,i;


 while( 1){

  memset(order,0,sizeof(int)*10000);

  printf("\nPlease input the size of the source array:");

  scanf("%d",&total);

  array = (int *)malloc(sizeof(int)*total + 4);

  printf("The source array as follow:\n");

  for(i = 0; i < total; i ++){

   array[i] = rand() % 10000;

   printf("%d ",array[i]);

   order[array[i]] ++; // 这里就是排序,够简洁吧 !

  }

  printf("\nThe array after by order as follow:\n");

  for(i = 0; i < 10000; i ++){

   while(order[i]){

    printf("%d ",i);

    order[i] --;

   }

  }

  free(array);

  printf("\nContinue(y/n)? :");

  getchar();

  i = getchar();

  if(isupper(i))

   i = tolower(i);

  if(i == 'n')

   break;

 }

 return 0;

}

@易语言代码编写例子


文件下载

来源:三叶资源网,欢迎分享,公众号:iisanye,(三叶资源网⑤群:21414575

已有1位网友发表了看法:

欢迎 发表评论:

百度站内搜索
关注微信公众号
三叶资源网⑤群:三叶资源网⑤群

网站分类
随机tag
易语言最新版识别精易皮肤模块视频上传工控之交通灯强行兼容高DPI多线程特训班趣生活登录会员管理系统PostgreSQL数据库国密算法置入汇编实时监控线程安全多进程md5效验天猫TX优图OCR鉴权手势验证码xm-sign算法
最新评论