Skip to content

Instantly share code, notes, and snippets.

@atharvashukla
Created April 20, 2020 20:32
Show Gist options
  • Save atharvashukla/0ad3a60024ab2a8ec386d001b52f946f to your computer and use it in GitHub Desktop.
Save atharvashukla/0ad3a60024ab2a8ec386d001b52f946f to your computer and use it in GitHub Desktop.
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