mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-09 05:56:06 +00:00
build
This commit is contained in:
@@ -283,11 +283,11 @@ comments: true
|
||||
List<List<double>> buckets = List.generate(k, (index) => []);
|
||||
|
||||
// 1. 将数组元素分配到各个桶中
|
||||
for (double num in nums) {
|
||||
// 输入数据范围 [0, 1),使用 num * k 映射到索引范围 [0, k-1]
|
||||
int i = (num * k).toInt();
|
||||
// 将 num 添加进桶 bucket_idx
|
||||
buckets[i].add(num);
|
||||
for (double _num in nums) {
|
||||
// 输入数据范围 [0, 1),使用 _num * k 映射到索引范围 [0, k-1]
|
||||
int i = (_num * k).toInt();
|
||||
// 将 _num 添加进桶 bucket_idx
|
||||
buckets[i].add(_num);
|
||||
}
|
||||
// 2. 对各个桶执行排序
|
||||
for (List<double> bucket in buckets) {
|
||||
@@ -296,8 +296,8 @@ comments: true
|
||||
// 3. 遍历桶合并结果
|
||||
int i = 0;
|
||||
for (List<double> bucket in buckets) {
|
||||
for (double num in bucket) {
|
||||
nums[i++] = num;
|
||||
for (double _num in bucket) {
|
||||
nums[i++] = _num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user