Created
October 19, 2012 06:34
-
-
Save sharat/3916556 to your computer and use it in GitHub Desktop.
radi sort
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 radix_sort(unsigned *begin, unsigned *end) | |
{ | |
unsigned *begin1 = new unsigned[end - begin]; | |
unsigned *end1 = begin1 + (end - begin); | |
for (unsigned shift = 0; shift < 32; shift += 8) { | |
size_t count[0x100] = {}; | |
for (unsigned *p = begin; p != end; p++) | |
count[(*p >> shift) & 0xFF]++; | |
unsigned *bucket[0x100], *q = begin1; | |
for (int i = 0; i < 0x100; q += count[i++]) | |
bucket[i] = q; | |
for (unsigned *p = begin; p != end; p++) | |
*bucket[(*p >> shift) & 0xFF]++ = *p; | |
std::swap(begin, begin1); | |
std::swap(end, end1); | |
} | |
delete[] begin1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment