JAVA,RadixSort,桶排序
public static void sort(List<String> element, int digits) { //digits-排列位数
@SuppressWarnings(" unchecked ")
List<String>[] buckets = (List<String>[]) new ArrayList[128];
try {
for (int n = digits - 1; n >= 0; n--) {
for (String i : element) {
if (i.length() < digits) {
throw new Exception("element" + '"' + i + '"' + " short than digit");
}
if (buckets[getBucket(i, n)] == null) {
buckets[getBucket(i, n)] = new ArrayList<>();
}
buckets[getBucket(i, n)].add(i);
}
element.clear();
for (int i = 0; i < buckets.length; i++) {
if (buckets[i] != null) {
for (int a = 0; a < buckets[i].size(); a++) {
element.add(buckets[i].get(a));
}
buckets[i].clear();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private static int getBucket(String value, int position) {
return value.charAt(position);
}