Created
March 14, 2016 19:45
-
-
Save valikos/b116f587171eff33da5f 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
var unsortArray = [3, 5, 2, 7, 6, 8, 9, 1, 0, 4] | |
function selectionSort(array) { | |
n = array.length; | |
for (i = 0; i < n - 1; i++) { | |
var smallest = i | |
for (j = i + 1; j < n; j++) { | |
if (array[j] < array[smallest]) { | |
smallest = j | |
} | |
} | |
var tmp = array[smallest]; | |
array[smallest] = array[i]; | |
array[i] = tmp; | |
} | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment