Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions sorting-algorithms-in-javascript/shellsort.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// array to sort
var array = [9, 2, 5, 6, 4, 3, 7, 10, 1, 8];
let array = [9, 2, 5, 6, 4, 3, 7, 10, 1, 8];

// gaps
var gaps = [701, 301, 132, 57, 23, 10, 4, 1];
let gaps = [701, 301, 132, 57, 23, 10, 4, 1];

function shellsort(array) {
for(var g = 0; g < gaps.length; g++) {
var gap = gaps[g];
for(var i = gap; i < array.length; i++) {
var temp = array[i];
for(var j = i; j >= gap && array[j - gap] > temp; j -= gap) {
for(let g = 0; g < gaps.length; g++) {
let gap = gaps[g];
for(let i = gap; i < array.length; i++) {
let temp = array[i];
for(let j = i; j >= gap && array[j - gap] > temp; j -= gap) {
array[j] = array[j - gap];
}
array[j] = temp;
Expand Down