快速排序

时间:2020-07-02 19:50:59   收藏:0   阅读:52

后续更新双端快排,以及Arrays.sort()中的三路快排。

    public void quickSort(int[] num,int start,int end){
        if (start>=end){
            return;
        }
        int i = start;
        int j = end;
        while(i<j){
            while(i<j && num[j]>=num[start]) j--;
            while(i<j && num[i]<=num[start]) i++;
            if (i<j){
                int temp = num[i];
                num[i] = num[j];
                num[j] = temp;
            }
        }
        int temp = num[start];
        num[start] = num[i];
        num[i] = temp;
        quickSort(num,start,i-1);
        quickSort(num,i+1,end);
    }
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!