Skip to content

Instantly share code, notes, and snippets.

@ButlerFuqua
Created April 12, 2021 11:31
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/b354db04e1dc5f38f1be20d0450b6fff to your computer and use it in GitHub Desktop.
Save ButlerFuqua/b354db04e1dc5f38f1be20d0450b6fff to your computer and use it in GitHub Desktop.
InsertionSort(numbers, numbersSize) {
i = 0
j = 0
temp = 0 // Temporary variable for swap
for (i = 1; i < numbersSize; ++i) {
j = i
// Insert numbers[i] into sorted part
// stopping once numbers[i] in correct position
while (j > 0 && numbers[j] < numbers[j - 1]) {
// Swap numbers[j] and numbers[j - 1]
temp = numbers[j]
numbers[j] = numbers[j - 1]
numbers[j - 1] = temp
--j
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment