Skip to content

Instantly share code, notes, and snippets.

@ButlerFuqua
Created April 12, 2021 11:32
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/cddb7be5c459f7ece4bf47d235a7f1d7 to your computer and use it in GitHub Desktop.
Save ButlerFuqua/cddb7be5c459f7ece4bf47d235a7f1d7 to your computer and use it in GitHub Desktop.
InsertionSortInterleaved(numbers, numbersSize, startIndex, gap) {
i = 0
j = 0
temp = 0 // Temporary variable for swap
for (i = startIndex + gap; i < numbersSize; i = i + gap) {
j = i
while (j - gap >= startIndex && numbers[j] < numbers[j - gap]) {
temp = numbers[j]
numbers[j] = numbers[j - gap]
numbers[j - gap] = temp
j = j - gap
}
}
}
ShellSort(numbers, numbersSize, gapValues) {
for each (gapValue in gapValues) {
for (i = 0; i < gapValue; i++) {
InsertionSortInterleaved(numbers, numbersSize, i, gapValue)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment