Find the minimum of the unsorted part and put it at the front. Always O(n²) comparisons but at most n − 1 swaps.
void selectionSort(int a[], int n) {
for (int i = 0; i < n - 1; i++) {
int minIdx = i;
for (int j = i + 1; j < n; j++)
if (a[j] < a[minIdx]) minIdx = j;
swap(a[i], a[minIdx]);
}
}