public static void RadixSort10(int[] a)
{
// バケツを用意
List<int>[] bucket = new List<int>[10];
for (int d = 0, r = 1; d < 3; ++d, r *= 10)
{
// バケツに値を入れる
for (int i = 0; i < a.Length; ++i)
{
int key = (a[i] / r) % 10; // a[i] の d 桁目だけを取り出す。
if (bucket[key] == null) bucket[key] = new List<int>();
bucket[key].Add(a[i]);
}
// バケツ中の値の結合
for (int j = 0, i = 0; j < bucket.Length; ++j)
if (bucket[j] != null)
foreach (int val in bucket[j])
a[i++] = val;
// バケツを一度空にする
for (int j = 0; j < bucket.Length; ++j)
bucket[j] = null;
}
}