|
1 | 1 | import 'package:algorithm_visualizer/features/sorting/base/view_model/sorting_notifier.dart'; |
2 | | -import 'package:collection/collection.dart'; |
3 | | -import 'package:flutter/material.dart'; |
4 | 2 |
|
5 | 3 | class InsertionSortNotifier extends SortingNotifier { |
6 | | - @override |
7 | | - Future<void> buildSort() async { |
8 | | - final list = List<SortableItem>.from(state.list); |
9 | | - |
10 | | - for (int i = 1; i < list.length; i++) { |
11 | | - if (operation != SortingEnum.played) return; |
12 | | - |
13 | | - SortableItem keyItem = list[i]; |
14 | | - int j = i - 1; |
15 | | - |
16 | | - while (j >= 0 && list[j].value > keyItem.value) { |
17 | | - if (operation != SortingEnum.played) return; |
18 | | - |
19 | | - list[j] = list[j].copyWith(sortedStatus: SortingStatus.compared); |
20 | | - list[j + 1] = list[j + 1].copyWith(sortedStatus: SortingStatus.compared); |
21 | | - state = state.copyWith(list: list); |
22 | | - await Future.delayed(speedDuration); |
23 | 4 |
|
24 | | - list.swap(j, j + 1); |
25 | | - |
26 | | - final positions = Map<int, Offset>.from(state.positions); |
27 | | - final temp = positions[list[j].id]!; |
28 | | - positions[list[j].id] = positions[list[j + 1].id]!; |
29 | | - positions[list[j + 1].id] = temp; |
30 | | - |
31 | | - state = state.copyWith(list: list, positions: positions); |
32 | | - await Future.delayed(speedDuration); |
33 | | - |
34 | | - list[j] = list[j].copyWith(sortedStatus: SortingStatus.unSorted); |
35 | | - list[j + 1] = list[j + 1].copyWith(sortedStatus: SortingStatus.unSorted); |
36 | | - state = state.copyWith(list: list); |
37 | | - j--; |
38 | | - } |
39 | | - } |
40 | | - |
41 | | - await greenSortedItemsAsDone(); |
| 5 | + @override |
| 6 | + List<SortingStep> buildSorting(List<int> values) { |
| 7 | + // TODO: implement buildSorting |
| 8 | + throw UnimplementedError(); |
42 | 9 | } |
43 | 10 | } |
0 commit comments