From 8c4aaa6f60c6fa9e8d34d894161ff64257ea7460 Mon Sep 17 00:00:00 2001 From: blackhammer25 Date: Fri, 2 Oct 2020 00:47:49 +0530 Subject: [PATCH] added selection sort for dart --- Dart/selection_sort.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Dart/selection_sort.dart diff --git a/Dart/selection_sort.dart b/Dart/selection_sort.dart new file mode 100644 index 0000000..0fbb705 --- /dev/null +++ b/Dart/selection_sort.dart @@ -0,0 +1,18 @@ +void selectSorting(List list) { + if (list == null || list.length == 0) return; + int num = list.length; + int i, steps; + for (steps = 0; steps < num; steps++) { + for (i = steps + 1; i < num; i++) { + if(list[steps] > list[i]) { + change(list, steps, i); + } + } + } +} + +void change(List list, int steps, int i) { + int count = list[steps]; + list[steps] = list[i]; + list[i] = count; +} \ No newline at end of file