Untitled
Anonymous
plain_text
03/31/2023 7:56 AM
492 B
20
Indexable
void sort(int n, int *a) {
for (int i = 0; i < n; i++) {
int mn = a[i], pos = i;
for (int j = i + 1; j < n; j++) {
if (a[j] < mn) {
mn = a[j];
pos = j;
}
}
if (mn != a[i]) { //swap
int t = a[i];
a[i] = a[pos];
a[pos] = t;
}
}
}
Editor is loading...