Take one element as the pivot to separate two parts from another elements. For the convenient, we always takes the last element as the pivot.
There is a partition function, search the elements in the range [left:right - 1], if the element vec[j] is smaller than vec[piovt], call swap() for putting the smaller element to left side. On the contrary, put the larger element to right side.
Finally, ++i is very important, it means shifting the index to point the right side with larger elements. And, call swap() to move pivot to the middle between left side and right side.