This is part 2 of the previous question asked which is at - QuickSort C++ Implementation using Iterators.
Based on Jerry Coffin's answer, I have made the changes except for using templates.
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <utility>
typedef std::vector<int>::iterator itr;
itr partition(itr left,itr right)
{
itr i=left-1;
itr it=left;
while(it<right)
{
if(*it<*right)
{
using std::swap;
std::advance(i,1);
swap(*i,*it);
}
std::advance(it,1);
}
using std::swap;
swap(*(i+1),*right);
std::advance(i,1);
return i;
}
void quicksort(itr left, itr right)
{
if(std::distance(left,right)>=2)
{
itr q=partition(left,right);
quicksort(left,q-1);
quicksort(q+1,right);
}
}
int main()
{
std::vector<int> v={6,10,4,5,3,9,13,8};
std::copy(v.begin(),v.end(),std::ostream_iterator<int>(std::cout," "));
std::cout<<std::endl;
quicksort(std::begin(v),std::end(v)-1);
std::copy(v.begin(),v.end(),std::ostream_iterator<int>(std::cout," "));
std::cout<<std::endl;
return 0;
}