快速排序-java

 static int[] quickSort(int[] array, int L, int R) {

        int i = L;
        int j = R;
        int pivot = array[(L + R) / 2];

        while (i < j) {
            while (array[i] < pivot) {
                i++;
            }
            while (array[j] > pivot) {
                j--;
            }

            if (i <= j) {
                int temp = array[i];
                array[i] = array[j];
                array[j] = temp;
                i++;
                j--;
            }
        }

        if (j > L) {
            quickSort(array, L, j);
        }

        if (i < R) {
            quickSort(array, i, R);
        }
        System.out.println(Arrays.toString(array));
        return array;
    }

 

posted on 2017-09-08 15:41  Camork  阅读(135)  评论(0)    收藏  举报

导航