文字列ソート--下位優先
737 ワード
:
package com.lsd;
public class LSD {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] str = {"ab0","Hc2","cs3","ab0","sdg"};
sort(str, 3);
}
public static void sort(String[] a,int w) {
int N = a.length;
int R = 256;
int[] count = new int[R+1];
String[] aux = new String[N];
//
for (int i = 0; i < N; i++)
count[a[i].charAt(w-3)+1]++;
//
for (int r = 0; r < R; r++)
count[r+1] = count[r+1] + count[r];
//
for (int i = 0; i < N; i++)
aux[count[a[i].charAt(w-3)]++] = a[i];
//
for (int i = 0; i < N; i++)
System.out.println(aux[i]);
}
}