1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| function shellSort(nums) { let step = nums.length; while (step > 1) { step = ~~(step / 3) + 1; for(let i = step; i < nums.length; i++) { const temp = nums[i]; let j; for(j = i - step; j >= 0; j -= step) { if(nums[j] > temp) { nums[j + step] = nums[j]; }else { break; } } nums[j + step] = temp; } }
return nums; }
|