Created
December 15, 2017 15:16
-
-
Save alexnoz/a12fa7b02873b83038181574bff3e221 to your computer and use it in GitHub Desktop.
The Shell's sorting algorithm
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
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