Skip to content

Commit a6b4d10

Browse files
cleanup the code
1 parent 5764c89 commit a6b4d10

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:algorithm_visualizer/features/sorting/base/view_model/sorting_notifier.dart';
2+
import 'package:collection/collection.dart';
23

34
class BubbleSortNotifier extends SortingNotifier {
45
@override
@@ -13,14 +14,13 @@ class BubbleSortNotifier extends SortingNotifier {
1314
steps.add(SortingStep(index1: j, index2: j + 1, action: SortingStatus.compared)); // external
1415

1516
if (arr[j] > arr[j + 1]) {
16-
steps.add(SortingStep(index1: j, index2: j + 1, action: SortingStatus.swiping)); // external
17-
final tmp = arr[j];
18-
arr[j] = arr[j + 1];
19-
arr[j + 1] = tmp;
17+
steps.add(SortingStep(index1: j, index2: j + 1, action: SortingStatus.swapping)); // external
18+
19+
arr.swap(j, j + 1);
2020
isSorted = false;
2121
}
2222

23-
steps.add(SortingStep(index1: j, index2: j + 1, action: SortingStatus.swiped)); // external
23+
steps.add(SortingStep(index1: j, index2: j + 1, action: SortingStatus.swapped)); // external
2424
}
2525

2626
steps.add(SortingStep(

0 commit comments

Comments
 (0)