Skip to content

Commit dcefc8f

Browse files
committed
新增希尔排序
1 parent e3e2224 commit dcefc8f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
let shellSort = function () {
2+
//获取数组长度
3+
var size = this.items.length
4+
//初始化增量(间隔)
5+
var gap = Math.floor(size / 2)
6+
while (gap >= 1) {
7+
//gap分组,分组进行排序
8+
for (var i = gap; i < size; i++) {
9+
var temp = this.items[i]
10+
var j = i
11+
while (this.items[j - gap] > temp & j > gap - 1) {
12+
this.items[j] = this.items[j - gap]
13+
j -= gap
14+
}
15+
this.items[j] = temp
16+
}
17+
gap = Math.floor(gap / 2)
18+
}
19+
}

0 commit comments

Comments
 (0)