65816-llvm-mos/benchmarks/bubbleSort.c
2026-05-18 14:43:35 -05:00

13 lines
460 B
C

// Bubble-sort 16 ints. Exercises array indexed access, nested loops,
// and i16 compare/swap — patterns common in any sorted-collection code.
void bubbleSort(short *a, unsigned short n) {
for (unsigned short i = 0; i < n - 1; i++) {
for (unsigned short j = 0; j < n - 1 - i; j++) {
if (a[j] > a[j + 1]) {
short t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
}