data-structures · advanced · ~15 min
Recursive partitioning; pivot choice; tail-call shape.
Sort an int array ascending in place using recursive partitioning around a pivot.
Implement void quicksort(int *a, size_t n) that sorts the first n elements of a ascending, in place, using a partitioning scheme of your choice (Lomuto or Hoare). No main — the grader calls it.
a: pointer to a writable int array.n: the number of elements (may be 0).Nothing is returned. After the call a[0..n-1] is sorted ascending.
{5,2,8,1,9,3,7,4,6} -> {1,2,3,4,5,6,7,8,9}
{9,8,7,6,5,4,3,2,1} -> {1,2,3,4,5,6,7,8,9}
{3,3,3,3} -> {3,3,3,3}
n < 2 base case).Pointer a to a writable int array and a length n (n may be 0).
Nothing returned; a is sorted ascending in place.
Sort in place via recursive partitioning; handle the n < 2 base case.
#include <stddef.h>
void quicksort(int *a, size_t n) {
/* TODO */
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.