data-structures · intermediate · ~15 min

Bubble sort

Implement a simple comparison sort.

Challenge

Implement void bubble_sort(int *a, int n) sorting the first n elements in ascending order in place.

Starter code

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

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