Skip to content

Instantly share code, notes, and snippets.

@geektutor
Last active May 16, 2020 20:42
Show Gist options
  • Save geektutor/9c72a580c66a47880e200a6d01169298 to your computer and use it in GitHub Desktop.
Save geektutor/9c72a580c66a47880e200a6d01169298 to your computer and use it in GitHub Desktop.
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