@ -18,7 +18,7 @@ public class bucket_sort {
// 1. 将数组元素分配到各个桶中
foreach (float num in nums) {
// 输入数据范围 [0, 1),使用 num * k 映射到索引范围 [0, k-1]
int i = (int)num * k;
int i = (int) (num * k);
// 将 num 添加进桶 i
buckets[i].Add(num);
}
@ -17,7 +17,7 @@ func bucketSort(nums []float64) {
for _, num := range nums {
i := int(num) * k
i := int(num * float64(k))
buckets[i] = append(buckets[i], num)
@ -20,7 +20,7 @@ public class bucket_sort {
for (float num : nums) {
int i = (int) num * k;
buckets.get(i).add(num);
@ -12,7 +12,7 @@ func bucketSort(nums: inout [Double]) {
for num in nums {
let i = Int(num) * k
let i = Int(num * k)
buckets[i].append(num)