Operators for bit manipulation are the subject of
Radix sorting linked lists
stack *rsort(stack *my_stack)
{
int shift, i;
stack *bucket[256];
stack_object *first;
for(shift=0; shift<32; shift+=8)
{
for(i=0; i<256; i++)
bucket[i]=create_stack();
while(!(stack_is_empty(my_stack)))
{
first=top_of_stack(my_stack);
push_on_stack(first,bucket[((first->key)>>shift)&255]);
pop_stack(my_stack);
}
for(i=255; i>=0; i--)
while(!(stack_is_empty(bucket[i])))
{
first=top_of_stack(bucket[i]);
push_on_stack(first,my_stack);
pop_stack(bucket[i]);
}
}
return my_stack;
}
Radix sorting arrays
void rsort(record a[], int n)
{
int i,j;
int shift;
record temp[MAXLENGTH];
int bucket_size[256], first_in_bucket[256];
for(shift=0; shift<32; shift+=8)
{
/* compute the size of each bucket and
copy each record from array a to array temp */
for(i=0; i<256; i++)
bucket_size[i]=0;
for(j=0; j<n; j++)
{
i=(a[j].key>>shift)&255;
bucket_size[i]++;
temp[j]=a[j];
}
/* mark off the beginning of each bucket */
first_in_bucket[0]=0;
for(i=1; i<256; i++)
first_in_bucket[i]=first_in_bucket[i-1]+bucket_size[i-1];
/* copy each record from array temp to its bucket in array a */
for(j=0; j<n; j++)
{
i=(temp[j].key>>shift)&255;
a[first_in_bucket[i]]=temp[j];
first_in_bucket[i]++;
}
}
}