I am reading the definitions of radix, counting and bucket sorts and it seems that all of them are just the code below:
public static void sort(int[] a, int maxV
To sort an array using count sort:
#define MAX_INPUT 1000
void sort(int arr[100], int n)
{
static int hash[MAX_INPUT], i, j;
memset(hash, 0, sizeof hash);
for (i = 0; i < n; ++i) ++hash[arr[i]];
j = 0;
for (i = 0; i < MAX_INPUT; ++i)
while (hash[i]--)
arr[j++] = i;
}
This is just O(MAX_INPUT)
, thus sorting in linear time. For bucket sort, it is very different. Here is an implementation