publicclassLSD {privatestaticfinalint BITS_PER_BYTE = 8;
// do not instantiateprivateLSD() { }
/**
* Rearranges the array of W-character strings in ascending order.
*
* @param a the array to be sorted
* @param W the number of characters per string
*/publicstaticvoidsort(String[] a, int W) {
int N = a.length;
int R = 256; // extend ASCII alphabet size
String[] aux = new String[N];
for (int d = W-1; d >= 0; d--) {
// sort by key-indexed counting on dth character// compute frequency countsint[] count = newint[R+1];
for (int i = 0; i < N; i++)
count[a[i].charAt(d) + 1]++;
// compute cumulatesfor (int r = 0; r < R; r++)
count[r+1] += count[r];
// move datafor (int i = 0; i < N; i++)
aux[count[a[i].charAt(d)]++] = a[i];
// copy backfor (int i = 0; i < N; i++)
a[i] = aux[i];
}
}