bucket sort
Uses bucket sort on an array of integers. Prereq: void printArray(int [], int).
void bucketSort(int array[]) { int buckets[10][SIZE] = {0}; int largest = array[0]; int divider = 10; int count = 0; int place_value = 1; int digit = 0;
for (int x = 0; x <= SIZE - 1; x++) { if (array[x] > largest) largest = array[x]; }
while (largest >= divider) { for (int x = 0; x <= SIZE - 1; x++) { count = 0; if (place_value == 1) { while (buckets[array[x] % divider][count]) count++;
buckets[array[x] % divider][count] = array[x]; } else if (place_value > 1) { digit = (array[x] / divider) % 10;
while (buckets[digit][count]) count++;
buckets[digit][count] = array[x]; } }
count = 0;
for (int x = 0; x <= 9; x++) { for (int y = 0; y <= SIZE - 1; y++) { if (buckets[x][y]) { array[count] = buckets[x][y]; buckets[x][y] = 0; count++; } } }
if (place_value > 1) divider *= 10;
place_value++; }
printArray(array); }










