快速排序

/**
     * 快速排序
     * @param numbers
     * @param left
     * @param right
     */
    static void quickSort(int[] numbers,int left,int right){
        System.out.println(Arrays.toString(numbers));
        if(left < right) {
            int i = left,j = right;
            int x = numbers[left];
            while(i < j) {
                while(i < j&& numbers[j] >= x){
                    j--;
                }        
                if(i < j){
                    numbers[i++] = numbers[j];
                }
                while(i < j&&numbers[i] <= x ){
                    i++;
                }
                if (i < j) {
                    numbers[j--] = numbers[i];
                }
            }
            numbers[i] = x;
            
            quickSort(numbers, left, i);
            quickSort(numbers, i + 1, right);
            
        }
        
    }

 

posted @ 2016-02-16 15:35  phyxis_xu  阅读(89)  评论(0编辑  收藏  举报