Created
April 12, 2021 11:31
-
-
Save ButlerFuqua/b354db04e1dc5f38f1be20d0450b6fff 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
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