Update radix_sort.java

pull/270/head
Yudong Jin 2 years ago
parent dd40ca6931
commit 8ba1f64710

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