快度排序,还未验错

int partition(int *array,int p,int r)
{
    int partElement = *(array+r);
    int lastSmallerIndex = p-1;
    for(int j = p;j<=r-1;j++)
    {
        if(*(array+j)<=partElement )
        {
            lastSmallerIndex++;
            int temp = *(array+lastSmallerIndex);
            *(array+lastSmallerIndex) = *(array+j);
            *(array+j) = temp;
        }
    }
    
    *(array+r) = *(array+lastSmallerIndex+1);
    *(array+lastSmallerIndex+1) = partElement;
    
    return (lastSmallerIndex+1);
    
}
void quickSort(int *array,int p,int r)
{
    if(p<r){
        int q = partition(array,p,r);
        quickSort(array,p,q-1);
        quickSort(array,q+1,r);
        
    }
}
原文地址:https://www.cnblogs.com/pencilCool/p/4671952.html