Skip to content

Commit 59cc7bc

Browse files
change BubbleSortStep to SortingStep
1 parent b811d39 commit 59cc7bc

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

lib/features/sorting/base/helper/sortable_item.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,15 @@ class SortableItem {
1919
);
2020
}
2121
}
22+
23+
class SortingStep {
24+
final int index1;
25+
final int index2;
26+
final SortingStatus action;
27+
28+
SortingStep({
29+
required this.index1,
30+
required this.index2,
31+
required this.action,
32+
});
33+
}

lib/features/sorting/bubble/view_model/bubble_sort_notifier.dart

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,28 @@ class BubbleSortNotifier extends SortingNotifier {
6060
await greenSortedItemsAsDone();
6161
}
6262

63-
List<BubbleSortStep> bubbleSortSteps(List<int> values) {
64-
final steps = <BubbleSortStep>[];
63+
List<SortingStep> bubbleSortSteps(List<int> values) {
64+
final steps = <SortingStep>[];
6565
final arr = List<int>.from(values);
6666

6767
for (int i = 0; i < arr.length - 1; i++) {
6868
bool isSorted = true;
6969

7070
for (int j = 0; j < arr.length - i - 1; j++) {
71-
steps.add(BubbleSortStep(index1: j, index2: j + 1, action: SortingStatus.compared)); // external
71+
steps.add(SortingStep(index1: j, index2: j + 1, action: SortingStatus.compared)); // external
7272

7373
if (arr[j] > arr[j + 1]) {
74-
steps.add(BubbleSortStep(index1: j, index2: j + 1, action: SortingStatus.swapped)); // external
74+
steps.add(SortingStep(index1: j, index2: j + 1, action: SortingStatus.swapped)); // external
7575
final tmp = arr[j];
7676
arr[j] = arr[j + 1];
7777
arr[j + 1] = tmp;
7878
isSorted = false;
7979
}
8080

81-
steps.add(BubbleSortStep(index1: j, index2: j + 1, action: SortingStatus.unSorted)); // external
81+
steps.add(SortingStep(index1: j, index2: j + 1, action: SortingStatus.unSorted)); // external
8282
}
8383

84-
steps.add(BubbleSortStep(
84+
steps.add(SortingStep(
8585
index1: arr.length - i - 1, index2: arr.length - i - 1, action: SortingStatus.sorted)); // external
8686

8787
if (isSorted) break;
@@ -90,15 +90,3 @@ class BubbleSortNotifier extends SortingNotifier {
9090
return steps;
9191
}
9292
}
93-
94-
class BubbleSortStep {
95-
final int index1;
96-
final int index2;
97-
final SortingStatus action;
98-
99-
BubbleSortStep({
100-
required this.index1,
101-
required this.index2,
102-
required this.action,
103-
});
104-
}

0 commit comments

Comments
 (0)