码迷,mamicode.com
首页 > 编程语言 > 详细

桶排序

时间:2018-08-05 22:30:28      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:eof   include   fine   bucket   size   std   star   define   printf   

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 #define MAXINPUTNUM 5000
 5 
 6 typedef int ElementType;
 7 
 8 void BucketSort(ElementType *Array,int ArrayLen)
 9 {
10     int i;
11     int ArrayEnd;
12     int Buckets[MAXINPUTNUM];
13     memset(Buckets,0,sizeof(Buckets));
14     
15     for(i = 0;i < ArrayLen;i ++)
16     {
17         Buckets[Array[i]] ++;
18     }
19     
20     for(i = 0,ArrayEnd = 0;i < MAXINPUTNUM;i ++)
21     {
22         while(Buckets[i] --)
23         {
24             Array[ArrayEnd++] = i;
25         }
26     }
27 }
28 
29 int main()
30 {
31     ElementType TestArray[10] = {718,224,3332,4443,55,31,66,79,90,7};
32     BucketSort(TestArray,10);
33     int i;
34     for(i = 0;i < 10;i ++)
35     {
36         printf("%d ",TestArray[i]);
37     }
38     printf("\n");
39     return 0;
40 }

 

桶排序

标签:eof   include   fine   bucket   size   std   star   define   printf   

原文地址:https://www.cnblogs.com/Asurudo/p/9427443.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!