int partition(vector<int> &A, int p,int r)
{
int x=A[r];
int i=p-1;
for(int j=p;j<r;j++){
if (A[j]<x)
{
i=i+1;
swap(A[i],A[j]);
}
}
swap(A[i+1],A[r]);
return i+1;
}
void quicksort(vector<int> &A, int p,int r)
{
if (p<r)
{
int q=partition(A,p,r);
quicksort(A,p,q-1);
quicksort(A,q+1,r);
}
}
int main()
{
int a[]={2,8,7,1,3,5,6,4};
vector<int> A(a,a+8);
vector<int>::iterator iter ;
cout<<"Before:\t";
for(iter=A.begin();iter!=A.end();iter++)
{
cout<<*iter<<"\t";
}
cout<<endl;
quicksort(A,0,A.size()-1);
cout<<"After:\t";
for(iter=A.begin();iter!=A.end();iter++)
{
cout<<*iter<<"\t";
}
cout<<endl;
cin.get();
return 0;
}