Skip to content

Instantly share code, notes, and snippets.

@bradheintz
Created September 13, 2015 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradheintz/ba51be77bb77bf47b89d to your computer and use it in GitHub Desktop.
Save bradheintz/ba51be77bb77bf47b89d to your computer and use it in GitHub Desktop.
+ (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