Skip to content

Instantly share code, notes, and snippets.

@ButlerFuqua
Created April 12, 2021 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ButlerFuqua/3e296ae520b94b94d1a59d5d3393bbd4 to your computer and use it in GitHub Desktop.
Save ButlerFuqua/3e296ae520b94b94d1a59d5d3393bbd4 to your computer and use it in GitHub Desktop.
SelectionSort(numbers, numbersSize) {
i = 0
j = 0
indexSmallest = 0
temp = 0 // Temporary variable for swap
for (i = 0; i < numbersSize - 1; ++i) {
// Find index of smallest remaining element
indexSmallest = i
for (j = i + 1; j < numbersSize; ++j) {
if ( numbers[j] < numbers[indexSmallest] ) {
indexSmallest = j
}
}
// Swap numbers[i] and numbers[indexSmallest]
temp = numbers[i]
numbers[i] = numbers[indexSmallest]
numbers[indexSmallest] = temp
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment