Created
September 13, 2015 15:05
-
-
Save bradheintz/ba51be77bb77bf47b89d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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