SOURCE

const shellSort = function(arr) {
    const list = arr.slice()
    let len = list.length
    let gap = ~~(len / 2)

    // 根据间隔划分出小数组
    for (; gap > 0; gap = ~~(gap / 2)) {
        // 内部是插入排序
        for (let i = gap; i < len; i++) {
            for (let j = i; j > 0; j -= gap) {
                if (list[j] <= list[j - gap]) {
                    [list[j], list[j - gap]] =[list[j - gap], list[j]]
                }
            }
        }
    }
    return list
}

const arr = [6,4,7,3,8,2,9,1,5]
console.log(shellSort(arr))
console 命令行工具 X clear

                    
>
console