data-structures · intermediate · ~15 min

Bubble sort

A simple O(n²) sort; understand its invariants.

Challenge

Implement void bubble_sort(int *a, size_t n) sorting a ascending in place. Tested on arrays of various sizes including empty.

Starter code

#include <stddef.h>

void bubble_sort(int *a, size_t n) {
    /* TODO */
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.