快排中partition函数的几种写法记录

void swap(int *a, int *b) {
    if(a == b) return ;
    int temp = *a; 
    *a = *b; 
    *b = temp;
    return ;
}
int partition1(int *a, unsigned low, unsigned high) {
    if(low >= high) return 0;
    int i = 0;
    int pVotPos = low; //pVotPos指向根据pVotVal大小分割处的小
    int pVotVal = a[low];
    for(i=low+1;i<=high;i++) {
        if(a[i]= high) return 0;
    int i = 0;
    int pVotPos = low+1;  //pVotPos指向根据pVotVal大小分割处的大
    int pVotVal = a[low];
    for(i=low+1;i<=high;i++) {
        if(a[i]= high) return 0;
    int i = low, j = high;
    int pVotVal = a[low]; //把pVotPos的值存起来,并形成一个可用的槽
    while(ipVotVal && j>i) j--;    //从末端找小的
        a[i]=a[j];    //换到前面去
        while(a[i]

你可能感兴趣的:(C开发,算法,快排,partition,quicksort)