|
|
|
@ -49,12 +49,12 @@
|
|
|
|
|
for (int num : nums)
|
|
|
|
|
if (num > ma) ma = num;
|
|
|
|
|
// 按照从低位到高位的顺序遍历
|
|
|
|
|
for (int exp = 1; ma >= exp; exp *= 10)
|
|
|
|
|
// 对数组元素的第 k 位执行「计数排序」
|
|
|
|
|
// k = 1 -> exp = 1
|
|
|
|
|
// k = 2 -> exp = 10
|
|
|
|
|
// k = 3 -> exp = 100
|
|
|
|
|
// 即 exp = 10^(k-1)
|
|
|
|
|
for (int exp = 1; ma >= exp; exp *= 10)
|
|
|
|
|
// 对数组元素的第 k 位执行「计数排序」
|
|
|
|
|
countSort(nums, exp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -65,4 +65,3 @@
|
|
|
|
|
System.out.println("基数排序完成后 nums = " + Arrays.toString(nums));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|