DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Help with ->Straight Radix Sort

1. SpY
Registered User
Join Date
Jan 2005
Posts
9

## Help with ->Straight Radix Sort

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:
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);      } }  ```
can anyone help me with the main()

2. Code:
```  public static void main(String[] args) {
// make an integer array for sorting
int [] sortArray = {
5,3,8,6,4,1,9,2,0,7,8
};
// make an instance of the StraightRadixSort class
// invoke the StraightRadixSort class' sort() method
srs.sort(sortArray);
// print out the sorted array
for (int i=0;i<sortArray.length;i++) {
System.out.println(sortArray[i]);
}
}```

3. SpY
Registered User
Join Date
Jan 2005
Posts
9
sjalle
Thanks man ! tnx w much

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise
 Questions? Contact us. C++ Web Development Wireless Latest Tips Open Source

×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.