#include <iostream>
#include <vector>
using namespace std;
void quickSort(vector<int>&,int,int);
int partition(vector<int>&, int,int);
int main()
{
vector<int> A = {6,10,13,5,8,3,2,25,4,11};
int p=0;
int q=10;
cout<<"======Original======="<<endl;
for(auto e: A)
cout<< e <<" ";
cout<< endl;
quickSort(A,p,q);
cout<<"======Sorted======="<<endl;
for(auto e: A)
cout<< e <<" ";
cout<< endl;
}
void quickSort(vector<int>& A, int p,int q)
{
int r;
if(p<q)
{
r=partition(A, p,q);
quickSort(A,p,r);
quickSort(A,r+1,q);
}
}
int partition(vector<int>& A, int p,int q)
{
int x= A[p];
int i=p;
int j;
for(j=p+1; j<q; j++)
{
if(A[j]<=x)
{
i=i+1;
swap(A[i],A[j]);
}
}
swap(A[i],A[p]);
return i;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgcXVpY2tTb3J0KHZlY3RvcjxpbnQ+JixpbnQsaW50KTsKCmludCBwYXJ0aXRpb24odmVjdG9yPGludD4mLCBpbnQsaW50KTsKCmludCBtYWluKCkKewogICAgdmVjdG9yPGludD4gQSA9IHs2LDEwLDEzLDUsOCwzLDIsMjUsNCwxMX07CiAgICBpbnQgcD0wOwogICAgaW50IHE9MTA7CgogICAgY291dDw8Ij09PT09PU9yaWdpbmFsPT09PT09PSI8PGVuZGw7CiAgICBmb3IoYXV0byBlOiBBKQogICAgICAgIGNvdXQ8PCBlIDw8IiAiOwogICAgY291dDw8IGVuZGw7ICAgIAoKICAgIHF1aWNrU29ydChBLHAscSk7CgogICAgY291dDw8Ij09PT09PVNvcnRlZD09PT09PT0iPDxlbmRsOwogICAgZm9yKGF1dG8gZTogQSkKICAgICAgICBjb3V0PDwgZSA8PCIgIjsKICAgIGNvdXQ8PCBlbmRsOyAgIAp9CgoKdm9pZCBxdWlja1NvcnQodmVjdG9yPGludD4mIEEsIGludCBwLGludCBxKQp7CiAgICBpbnQgcjsKICAgIGlmKHA8cSkKICAgIHsKICAgICAgICByPXBhcnRpdGlvbihBLCBwLHEpOwogICAgICAgIHF1aWNrU29ydChBLHAscik7ICAKICAgICAgICBxdWlja1NvcnQoQSxyKzEscSk7CiAgICB9Cn0KCgppbnQgcGFydGl0aW9uKHZlY3RvcjxpbnQ+JiBBLCBpbnQgcCxpbnQgcSkKewogICAgaW50IHg9IEFbcF07CiAgICBpbnQgaT1wOwogICAgaW50IGo7CgogICAgZm9yKGo9cCsxOyBqPHE7IGorKykKICAgIHsKICAgICAgICBpZihBW2pdPD14KQogICAgICAgIHsKICAgICAgICAgICAgaT1pKzE7CgkJCXN3YXAoQVtpXSxBW2pdKTsKICAgICAgICB9CgogICAgfQoKICAgIHN3YXAoQVtpXSxBW3BdKTsKICAgIHJldHVybiBpOwp9