Skip to content

Commit eecda32

Browse files
authored
Merge pull request vJechsmayr#102 from MariaLuize/ShellSort/ShellSortJS
Shell Sort function in JS
2 parents c43cc15 + a542f19 commit eecda32

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎SortingAlgorithms/ShellSort.js‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//Language: Javascript
2+
//Author: Maria Luize
3+
//Github: https://github.com/MariaLuize
4+
function shellSort(arr) {
5+
var increment = arr.length / 2;
6+
while (increment > 0) {
7+
for (i = increment; i < arr.length; i++) {
8+
var j = i;
9+
var temp = arr[i];
10+
11+
while (j >= increment && arr[j-increment] > temp) {
12+
arr[j] = arr[j-increment];
13+
j = j - increment;
14+
}
15+
16+
arr[j] = temp;
17+
}
18+
19+
if (increment == 2) {
20+
increment = 1;
21+
} else {
22+
increment = parseInt(increment*5 / 11);
23+
}
24+
}
25+
return arr;
26+
}

0 commit comments

Comments
 (0)