#include <stdio.h>
int part(int arr[],int low,int high){
int pivot=arr[low];
while(low<high){
while(low<high && arr[high]>=pivot){
--high;
}
arr[low]=arr[high];
while(low<high && arr[low]<=pivot){
++low;
}
arr[high]=arr[low];
}
arr[low]=pivot;
return low;
}
void quickSort(int arr[],int low,int high){
if(low < high){
int pivotpos=part(arr,low,high);
quickSort(arr, low, pivotpos-1);
quickSort(arr, pivotpos+1, high);
}
return ;
}
void display(int a[], int size){
for (int i = 0; i < size; i++){
printf("%d ", a[i]);
}
printf("\n");
}
int main () {
printf("第一次测试用例:\n");
int arr[]={4, 1, 7, 8, 3, 9, 2};
printf("排序前:");
display(arr, 7);
quickSort(arr, 0, 6);
printf("排序后:");
display(arr, 7);
printf("第二次测试用例:\n");
int arr1[]={5, 1, 3, -1, 2, -10, 9, 0};
printf("排序前:");
display(arr1, 8);
quickSort(arr1, 0, 7);
printf("排序后:");
display(arr1, 8);
printf("第二次测试用例:\n");
int arr2[]={-5, -1, -7, -1, -2, -10, -9, 0};
printf("排序前:");
display(arr2, 8);
quickSort(arr2, 0, 7);
printf("排序后:");
display(arr2, 8);
return 0;
}