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/fc6cedfc1973eb60960f to your computer and use it in GitHub Desktop.
Save bradheintz/fc6cedfc1973eb60960f to your computer and use it in GitHub Desktop.
+ (void)hexadecimalRadixSort2:(int[])input length:(int)l {
int max = [self findMax:input length:l];
int partiallySorted[l];
int i;
int powerOf16 = 0;
int bin[16];
while ((1 << (powerOf16 << 2)) < max) {
for (int i = 0; i < 16; i++) bin[i] = 0;
for (i = 0; i < l; i++) bin[(input[i] >> (powerOf16 << 2)) & 0x0f]++; // get counts of current digits
for (i = 1; i < 16; i++) bin[i] += bin [i - 1]; // convert counts to array indices
for (i = l - 1; i >= 0; i--) partiallySorted[--bin[(input[i] >> (powerOf16 << 2)) & 0x0f]] = input[i];
for (i = 0; i < l; i++) input[i] = partiallySorted[i];
powerOf16++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment