lib/algorithm/qsort.js
function qsort(array, l, r, func) {
    if(l < r) {
        var i = l, j = r;
        var x = array[l];

        while(i < j) {
            while(i < j && func(x, array[j])) j--;
            array[i] = array[j];
            while(i < j && func(array[i], x)) i++;
            array[j] = array[i];
        }
        array[i] = x;

        qsort(array, l, i - 1, func);
        qsort(array, i + 1, r, func);
    }
}
function qsort(array, l, r, func) {
    if(l < r) {
        var i = l, j = r;
        var x = array[l];

        while(i < j) {
            while(i < j && func(x, array[j])) j--;
            array[i] = array[j];
            while(i < j && func(array[i], x)) i++;
            array[j] = array[i];
        }
        array[i] = x;

        qsort(array, l, i - 1, func);
        qsort(array, i + 1, r, func);
    }
}
function qsort ( array , l , r , func ) { if ( l < r ) { var i = l , j = r ; var x = array [ l ] ; while ( i < j ) { while ( i < j && func ( x , array [ j ] ) ) j -- ; array [ i ] = array [ j ] ; while ( i < j && func ( array [ i ] , x ) ) i ++ ; array [ j ] = array [ i ] ; } array [ i ] = x ; qsort ( array , l , i - 1 , func ) ; qsort ( array , i + 1 , r , func ) ; } }
qsort main function

@param array
@param l
@param r
@param func
@return
qsort main function