数据结构——快速排序 小猪猪0

#include <stdio.h>

int partition(int A[], int low, int high){
    // 19,3,6,9,2,4
    int privot = A[low];// 19 0
    while(low<high){
        while(low<high && A[high] >= privot) --high;
        A[low] = A[high];// 
        while(low<high && A[low] <= privot) ++low;
        A[high] =A[low];
    }
    A[low] = privot;
    return low;
}

void quick_sort(int A[], int low, int high){
    if(low < high){
        int privotpos = partition(A,low,high);
    
        quick_sort(A,low,privotpos-1); //左
        quick_sort(A,privotpos+1,high); //右
    }
}
void show(int A[]){
    for(int i=0;i<6;i++){
        printf("%d,",A[i]);
    }
    printf("\r\n");
}
int main(void) { 
	int A[] = {19,3,6,9,2,4};
	show(A);
	quick_sort(A,0,5);
	show(A);
	return 0;
}
原文地址:https://www.cnblogs.com/jianjunliu/p/15650110.html