I must make a class wich read 10 numbers eg 5,3,8,6,4,1,9,2,0,7,8
and sort them with Straight Radix Algorithm!
the Algorithm is:
can anyone help me with the main()PHP Code:class StraightRadixSort {
static final int w = 7, m = 1;
static final int M = (int) Math.pow(2, m);
int bits(int x, int k, int j)
{ return (x >> k) & ~(~0 << j); }
void straightradix(int a[]) {
int i, j, pass, N = a.length;
int b[] = new int[N];
int count[] = new int[M];
for (pass = 0; pass < w/m; pass++) {
for (j = 0; j < M; j++) count[j] = 0;
for (i = 0; i < N; i++)
count[bits(a[i], pass*m, m)]++;
for (j = 1; j < M; j++)
count[j] += count[j-1];
for (i = N-1; i >= 0; i--)
b[--count[bits(a[i], pass*m, m)]] = a[i];
for (i = 0; i < N; i++) { a[i] = b[i]; }
}
}
void sort(int a[]) {
straightradix(a);
}
}



Reply With Quote



Bookmarks