Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (30 sloc) 577 Bytes
#include <stdio.h>
#include <stdlib.h>
void f(int* a, int n, int b)
{
int *m = malloc(sizeof(int) * n * 2), *x = m, *y = m + n, *p = x, *q = y, i;
for (i = 0; i < n; i++)
{
int** r = a[i] & b ? &q : &p;
**r = a[i];
(*r)++;
}
if (b && p - x > 1)
f(x, p - x, b >> 1);
if (b && q - y > 1)
f(y, q - y, b >> 1);
for (; x != p; x++, a++)
*a = *x;
for (; y != q; y++, a++)
*a = *y;
free(m);
}
int main(void)
{
int a[] = {31, 41, 59, 26, 53, 58, 97, 93, 23, 84}, i;
f(a, 10, 64);
for (i = 0; i < 10; i++)
printf("%d ", a[i]);
printf("\n");
return 0;
}
Jump to Line
Something went wrong with that request. Please try again.