Instantly share code, notes, and snippets.

Embed
What would you like to do?
+ (void)paramRadixSort:(int*)input length:(int)l radix:(int)r {
int max = [self findMax:input length:l];
int partiallySorted[l];
int i;
int sigDig = 1;
int bin[r];
while (sigDig < max) {
for (int i = 0; i < r; i++) bin[i] = 0;
for (i = 0; i < l; i++) bin[(input[i] / sigDig) % r]++; // get counts of current digits
for (i = 1; i < r; i++) bin[i] += bin [i - 1]; // convert counts to array indices
for (i = l - 1; i >= 0; i--) partiallySorted[--bin[(input[i] / sigDig) % r]] = input[i];
for (i = 0; i < l; i++) input[i] = partiallySorted[i];
sigDig *= r;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment