Created
December 11, 2018 10:36
-
-
Save SajidK25/6c8cd57050961d2532ed033002efc704 to your computer and use it in GitHub Desktop.
Selection Sort Implementation using Dart Programming Language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void selectionSort(var L) { | |
var n = L.length; | |
for (var i = 0; i < n - 1; i++) { | |
var index_min = i; | |
for (var j = i + 1; j < n; j++) { | |
if (L[j] < L[index_min]) { | |
index_min = j; | |
} | |
} | |
if (index_min != i) { | |
var temp = L[i]; | |
L[i] = L[index_min]; | |
L[index_min] = temp; | |
} | |
} | |
} | |
void main() { | |
print("==============Acending order============="); | |
var lst = [8,1,77,12,67,5,19,4,7,10,100]; | |
print("Before sort lst: ${lst}"); | |
selectionSort(lst); | |
print("After sort lst: ${lst}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment