Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
368 B
7
Indexable
Never
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;
        }
    }
}