static void RadixSort(int[]arr) {
int[,] bucket = new int[10, arr.Length];
int[] bucketIndexSize = new int[10];
int count = 1;
int max = arr[0];
for (int i=1;i<arr.Length;i++) {
if (arr[i] > max) {
max = arr[i];
}
}
while (max / count != 0) {
//把数据放桶里面
for (int i = 0; i < arr.Length; i++) {
int index = arr[i] / count % 10;
bucket[index, bucketIndexSize[index]] = arr[i];
bucketIndexSize[index]++;
}
//把数据从桶里返回出来
int arrIndex = 0;
for (int i = 0; i < bucket.GetLength(0); i++) {
if (bucketIndexSize[i] > 0) {
for (int j = 0; j < bucketIndexSize[i];j++) {
arr[arrIndex++] = bucket[i, j];
}
}
}
count *= 10;
}
}
个人理解基数排序是把个位十位依次进行排序