快速排序

2019-08-26  本文已影响0人  GGatsby
function quickSort(arr, low, high) {
    var i = low;
    var j = high;
    var temp = arr[low];

    while(i<j){
        while(i<j && arr[j]>=temp)j--;
        arr[i] = arr[j];

        while(i<j && arr[i]<=temp)i++;
        arr[j] = arr[i];
    }

    arr[i] = temp;

    i-1>low && quickStart(arr, low, i-1);
    i+1<high && quickStart(arr, i+1, high);
}

var arr = [123,4,5,0,-1,98,42,65,77,100];

image.png
上一篇下一篇

猜你喜欢

热点阅读