更新快排中的partition

这一次是将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};
        
    }
原文地址:https://www.cnblogs.com/lijins/p/10153847.html