Created
April 20, 2020 20:32
-
-
Save atharvashukla/0ad3a60024ab2a8ec386d001b52f946f to your computer and use it in GitHub Desktop.
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
function swap(A, i, j) { | |
var tmp = A[i]; | |
A[i] = A[j]; | |
A[j] = tmp; | |
} | |
function selectionSort(A, n) { | |
let i = 0 | |
while (i < n) { | |
let m = i | |
let j = i + 1 | |
while (j < n) { | |
if (A[j] < A[m]) { | |
m = j | |
} | |
j = j + 1 | |
} | |
swap(A, i, m) | |
i = i + 1 | |
} | |
return A | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment