SOURCE

// 实现以下函数
function sort1(q, l , r) {
    if (l >= r) return;

    let i = l - 1, j = r + 1, x = q[l + r >> 1];
    while (i < j)
    {
        do i ++ ; while (q[i] < x);
        do j -- ; while (q[j] > x);
        if (i < j){
            let t = q[i];
            q[i] = q[j];
            q[j] = t;
        }
    }
    sort1(q, l, j), sort1(q, j + 1, r);
}
function sort(arr) {
    sort1(arr, 0, arr.length - 1);
    return '['+arr+']';
}
const nums = [2, 4, 1, 6, 5, 3, 7];
// 输出 [1, 2, 3, 4, 5, 6, 7]
console.log(sort(nums));
console 命令行工具 X clear

                    
>
console