码迷,mamicode.com
首页 > 其他好文 > 详细

更新快排中的partition

时间:2018-12-21 13:20:45      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:++   inf   bubuko   png   com   swa   wap   static   []   

技术分享图片

这一次是将partition 过程中, 维护三个区域。 <x   =x  >x  三区域。 还有个待定的区域。

 

    /*
     * 将数组划分为三个分区, 小于arr[R], 等于arr[R], 大于arr[R];
     */
    public static int[] partion01(int arr[], int L, int R){
        int less = L-1;
        int more = R;
        int cur = L;
        while( cur < more ){
            if( arr[cur] < arr[R] ){
                swap(arr, ++less, cur++);
            }else if( arr[cur] > arr[R] ){
                swap(arr, --more, cur);
            }else {
                cur++;
            }
        }
        swap(arr, more, R);
        return new int[] {less+1,more};
        
    }

 

更新快排中的partition

标签:++   inf   bubuko   png   com   swa   wap   static   []   

原文地址:https://www.cnblogs.com/lijins/p/10153847.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!