Radix Sort
Radix sort is a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value.
static void RadixSort(int* data, int count) {
int i, j;
int* temp = new int[count];
for (int shift = 31; shift > -1; --shift)
{
j = 0;
for (i = 0; i < count; ++i)
{
bool move = (data[i] << shift) >= 0;
if (shift == 0 ? !move : move)
data[i - j] = data[i];
else
temp[j++] = data[i];
}
for (int i = 0; i < j; i++)
{
data[(count - j) + i] = temp[i];
}
}
delete temp;
}
Example
int data[] = { -1, 25, -58964, 8547, -119, 0, 78596 };
RadixSort(data, 7);
Output
-58964
-119
-1
0
25
8547
78596