首页 > 编程语言 > 详细

快速排序

时间:2020-07-02 19:43:52      阅读:64      评论:0      收藏:0      [点我收藏+]

后续更新双端快排,以及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);
    }

快速排序

原文:https://www.cnblogs.com/wliamchen/p/13226467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!