Last active
May 16, 2020 20:42
-
-
Save geektutor/9c72a580c66a47880e200a6d01169298 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 main() { | |
selectionSort([3, 6, 4, 3, 4, 5]); | |
} | |
/* An implemention of selection sort in dart. Used Python knowledge for this */ | |
selectionSort(List sortList) { | |
for (var i = 0; i < sortList.length; i++) { | |
/* Loop through the list */ | |
for (var j = i + 1; j < sortList.length; j++) { | |
if (sortList[i] > sortList[j]) { | |
/* Check if the ith item is greater than the jth item, if yes, swap positions */ | |
int temp = sortList[i]; | |
sortList[i] = sortList[j]; | |
sortList[j] = temp; | |
} | |
} | |
} | |
print(sortList); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment