Challenge: Implement Partition

The partition function should partition the subarray array[pr]array[p \cdots r] so that all elements in array[pq1]array[p \cdots q-1] are less than or equal to array[q]array[q] (the pivot) and all elements in array[q+1r]array[q+1 \cdots r] are greater than array[q]array[q], and it returns the index qq of where the pivot ends up.

Use the provided swap() function for swapping.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy