Skip to content

Commit 516814a

Browse files
reformat the code
1 parent 61aae51 commit 516814a

File tree

1 file changed

+0
-6
lines changed

1 file changed

+0
-6
lines changed

lib/features/sorting/bucket/view_model/bucket_sort_notifier.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,17 @@ class BucketSortNotifier extends SortingNotifier {
1515
int maxVal = arr.reduce((a, b) => a > b ? a : b);
1616
int minVal = arr.reduce((a, b) => a < b ? a : b);
1717

18-
// Decide number of buckets (basic choice = n)
1918
int bucketCount = n;
2019
double bucketRange = (maxVal - minVal + 1) / bucketCount;
2120

22-
// 1. Create buckets
2321
final buckets = List.generate(bucketCount, (_) => <int>[]);
2422

25-
// 2. Scatter: put array elements into buckets
2623
for (int value in arr) {
2724
int bucketIndex = ((value - minVal) / bucketRange).floor();
2825
if (bucketIndex >= bucketCount) bucketIndex = bucketCount - 1;
2926
buckets[bucketIndex].add(value);
3027
}
3128

32-
// 3. Sort each bucket (Insertion Sort)
3329
for (var bucket in buckets) {
3430
for (int i = 1; i < bucket.length; i++) {
3531
int key = bucket[i];
@@ -42,7 +38,6 @@ class BucketSortNotifier extends SortingNotifier {
4238
}
4339
}
4440

45-
// 4. Gather: merge buckets back into arr
4641
int index = 0;
4742
for (var bucket in buckets) {
4843
for (int value in bucket) {
@@ -59,7 +54,6 @@ class BucketSortNotifier extends SortingNotifier {
5954
}
6055
}
6156

62-
// Mark all sorted at the end
6357
steps.add(SortingStep(index1: arr.length - 1, index2: arr.length - 1, action: SortingStatus.sorted));
6458

6559
return SortingResult(sortedValues: arr, steps: steps);

0 commit comments

Comments
 (0)