#include <iostream>
using namespace std;
const int N = 10;
int data[]= {6,1,2,7,9,3,4,5,10,8};
void quickSort(int* data, int low,int high);
void printArray(int* data, int n);
int partition(int* data,int low, int high);
int main()
{
quickSort(data,0,N-1);
printArray(data,N);
return 0;
}
void quickSort(int* data, int low, int high)
{
if(low>=high) return;
int key = partition(data,low,high);
quickSort(data,low,key-1);
quickSort(data,key+1,high);
}
void printArray(int* data, int n)
{
for(int i=0;i<n;++i)
{
cout<<data[i]<<" ";
}
cout<<endl;
}
int partition(int* data,int l, int h)
{
int low=l,high=h;
int temp = data[low];
while(low<high)
{
while(low<high && data[high]>=temp)
while(low<high && data[low]<=temp) ++low;
if(low<high)
{
data[low] ^= data[high];
data[high] ^= data[low];
data[low] ^= data[high];
}
}
data[l] = data[low];
data[low] = temp;
return low;
}