First of all, the code looks correct. Kudos.
Few notes though.
No naked loops. Every loop implements an important algorithm, and therefore deserves a name. In your case, the loop
for (int* i = p+1; i <= tmpStop; ++i)partitions the range. Lift it into a
partitionfunction. Not only it will make the code more readable, but also more testable. Now you can unit testpartition. And more maintainable too: you may change the partitioning strategy and not touch the core of sorting.Most range algorithms are more naturally expressed in terms of a semi-open range (that is, the
enddoes not belong to the range, but is one-beyond). With such contract you don't need to-1anywhere, and you may use<instead of<=.I am not sure that
std::vectoris the best choice to represent the stack. STL conveniently offers a stack container.flipis likely inferior tostd::swap.Stop using namespace std. It is a bad habit.