Thứ Năm, 28 tháng 8, 2014

Thuật toán Quick Sort

void quicksort(int a[10000] , int n , int low, int high) {
    /**< sap xep theo chieu tang dan  */
    int i = low ;
    int j = high ;
    int x = a[(low+high) /2] ;
    do {
        while (a[i] < x) i++ ;
        while (a[j]> x ) j -- ;
        if(i<=j) {
            int temp = a[i] ;
            a[i] = a[j] ;
            a[j] = temp ;
            i++ ;
            j-- ;
        }
    }
    while (i<= j) ;
    if( low<j) quicksort(a,n,low,j) ;
    if(i<high ) quicksort(a,n,i,high) ;
}

Không có nhận xét nào:

Đăng nhận xét