#include <stdio.h>
int partition(int* a, int p, int r)
{
int i = p-1;
int x = a[r-1];
for (int j=p; j<r; j++) {
if (a[j-1] <= x) {
i++;
int temp;
temp = a[j-1];
a[j -1] = a[i-1];
a[i-1] = temp;
}
}
int temp;
temp = a[i];
a[i] = a[r-1];
a[r-1] = temp;
return i+1;
}
void quick_sort(int* a, int p,int r)
{
if (p < r) {
int q = partition(a, p, r);
quick_sort(a, p, q-1);
quick_sort(a, q+1, r);
}
}
int main()
{
int a[] = {2,8,5,4,7,9,11,1};
int size = sizeof a / sizeof a[0];
quick_sort(a, 1, size);
printf(" The final result is :");
for(int i=0;i<size;i++)
printf("[%d] ",a[i]);
return 0;
}