[排序]桶排序
说明
unsorted[ ]
为未排序数组length
为未排序数组长度Max
为数组unsorted
中最大值的范围
使用方法
bucket_sort(数组,长度,范围)
模板
void bucket_sort(int unsorted[], int length, int Max)
{
int buckets[Max];
memset(buckets, 0, max*sizeof(int));
for(int i = 0; i < length; i++)
buckets[unsorted[i]]++;
for (int i = 0, j = 0; i < Max; i++)
while( (buckets[i]--) >0 )
unsorted[j++] = i;
}