/*
quicksort.c
Author: Zoro
Date: 2019/11/8
function: 快速排序
QuickSort pivot partition
*/
#include<stdio.h>
void quickSort(int arr[], int L, int R) {
int i = L;
int j = R;
int pivot = arr[(L + R) / 2];
while (i <= j) {
while (arr[i] < pivot) {
i++;
}
while (arr[j] > pivot) {
j--;
}
if (i <= j) {
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
i++;
j--;
}
}
if (L < j) {
quickSort(arr, L, j);
}
if (i < R) {
quickSort(arr, i, R);
}
}
int main() {
int arr[] = {6, 7, 8, 4, 3, 2, 9, 1, 5};
int i;
quickSort(arr, 0, 8);
for (i = 0; i < 9; i++) {
printf("%d\n", arr[i]);
}
return 0;
}