Quick_Sort

public class Quick_sort {
    public static void sort(int a[],int low,int high){
        int num = low;
        int temp;
        int i = high;
        int j = low;
        while (i != j){
            for(i = high; i > num; i--){
                if(a[i] < a[num]){
                    temp = a[i];
                    a[i] = a[num];
                    a[num] = temp;
                    
                    num = i;
                    break;
                }
            }
            
            for(j = low; j < num; j++){
                if(a[j] > a[num]){
                    temp = a[j];
                    a[j] = a[num];
                    a[num] = temp;
                    
                    num = j;
                    break;
                }
            }
        }
        if(low < num-1)
        sort(a,low,num-1);
        if(high > num+1)
        sort(a,num+1,high);
    }
    
    public static void main(String[] args){
        int[] a = {8,5,3,9,11,6,4,1,10,7,2};
        sort(a,0,a.length-1);
        for(int i : a){
            System.out.println(i);
        }
    }
}

 

posted @ 2013-12-03 21:35  xiaohuoshan  阅读(187)  评论(0编辑  收藏  举报