dongnguyenltqb
6/23/2018 - 2:44 AM

quicksort.js

function qs(l, r,a) {
    var i = l;
    var j = r;
    var key = a[Math.floor((l + r) / 2)];
    do {
        while (a[i] < key) i++;
        while (a[j] > key) j--;
        if (i <= j) {
            let t = a[i];
            a[i] = a[j];
            a[j] = t;
            i++;
            j--;
        }
    } while (i <= j);
    if (l < j) qs(l, j,a);
    if (i < r) qs(i, r,a)
}