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(" "); 39 return 0; 40 }