Skip to content

Instantly share code, notes, and snippets.

@alexnoz
Created December 15, 2017 15:16
Show Gist options
  • Save alexnoz/a12fa7b02873b83038181574bff3e221 to your computer and use it in GitHub Desktop.
Save alexnoz/a12fa7b02873b83038181574bff3e221 to your computer and use it in GitHub Desktop.
The Shell's sorting algorithm
function shellsort (arr) {
const getGap = l => Math.floor(l / 2)
let gap = getGap(arr.length)
while ((gap = getGap(gap)) > 0) {
for (let i = gap; i < arr.length; i++) {
const temp = arr[i]
for (var j = i; j >= gap && arr[j - gap] > temp; j -= gap)
arr[j] = arr[j - gap]
arr[j] = temp
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment