快速排序算法

@Test
public void testQuickSort(){
    int[] arr = {10,2,4,7,62,3,4,1,8,9,19};
    quickSort(arr, 0, arr.length-1);
        System.out.println(Arrays.toString(arr));
}

private void quickSort(int[] arr,int low, int high) {
    int i, j,temp,t;
    if(low > high){
        return;
    }
    i = low;
    j = high;
    temp=arr[i];
    while (i<j){
        while (arr[j]>=temp && i<j)
            j--;
        while (arr[i]<=temp && i<j)
            i++;
        if(i<j){
            t = arr[i];
            arr[i] = arr[j];
            arr[j] = t;
        }
    }
    arr[low] = arr[i];
    arr[i] = temp;
    quickSort(arr,low,i-1);
    quickSort(arr,i+1,high);
}

 

posted @ 2018-04-16 14:10  剑小破  阅读(128)  评论(0编辑  收藏  举报