One Pass Of Lomuto
int partition(std::vector<int> &a, int lo, int hi) {
int pivot = a[hi];
int i = lo - 1;
for (int j = lo; j < hi; j++)
if (a[j] <= pivot) std::swap(a[++i], a[j]);
std::swap(a[i + 1], a[hi]);
return i + 1;
}
The array is [8, 3, 11, 5, 2, 9, 4] and the call is partition(a, 0, 6). What is the array when the function returns?
Sign in to answer questions and track your progress
Sign In