Open pwstrick opened 4 years ago
function shellSort(arr) { var len = arr.length, gap = 0, temp; while (gap < len / 5) { //动态定义步长序列 gap = gap * 5 + 1; } for (; gap > 0; gap = Math.floor(gap / 5)) { for (var i = gap; i < len; i++) { temp = arr[i]; for (var j = i - gap; j >= 0 && arr[j] > temp; j -= gap) { arr[j + gap] = arr[j]; } arr[j + gap] = temp; } } return arr; }