2020-02-20 23:40:10 +00:00
|
|
|
#define RADIX 256
|
2020-12-23 23:27:18 +00:00
|
|
|
#define N 16
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
U8 a[N];
|
|
|
|
|
2020-02-16 00:26:51 +00:00
|
|
|
class List
|
2020-02-15 20:01:48 +00:00
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
List *next;
|
2020-12-23 23:27:18 +00:00
|
|
|
U8 *a;
|
|
|
|
|
|
|
|
} l[N], *r[RADIX];
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
U0 DumpIn()
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 i;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
"$$RED$$\n\nInput$$FG$$\n";
|
2020-12-23 23:27:18 +00:00
|
|
|
for (i = 0; i < N; i++)
|
|
|
|
"%d:%d\n", i, a[i];
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 DumpOut()
|
|
|
|
{
|
2020-12-23 23:27:18 +00:00
|
|
|
I64 i, j = 0;
|
2020-02-20 23:40:10 +00:00
|
|
|
List *tmpl;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
"$$RED$$\n\nOutput$$FG$$\n";
|
2020-12-23 23:27:18 +00:00
|
|
|
for (i = 0; i < RADIX; i++)
|
|
|
|
{
|
|
|
|
tmpl = r[i];
|
|
|
|
while (tmpl)
|
|
|
|
{
|
|
|
|
"%d:%d\n", j++, *tmpl->a;
|
|
|
|
tmpl = tmpl->next;
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 Init()
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 i;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
|
|
|
MemSet(r, 0, sizeof(r));
|
|
|
|
for (i = 0; i < N; i++)
|
|
|
|
{
|
|
|
|
a[i] = RandU16&255;
|
|
|
|
l[i].next = NULL;
|
|
|
|
l[i].a = &a[i];
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 Sort()
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
I64 i;
|
2020-12-23 23:27:18 +00:00
|
|
|
|
|
|
|
for (i = 0; i < N; i++)
|
|
|
|
{
|
|
|
|
l[i].next = r[*l[i].a];
|
|
|
|
r[*l[i].a] = &l[i];
|
2020-02-20 23:40:10 +00:00
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U0 RadixSort()
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
Init;
|
|
|
|
DumpIn;
|
|
|
|
Sort;
|
|
|
|
DumpOut;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RadixSort;
|