Is this the algorithm you mean?
Code:
void mystery_sort(int a[], int n) {
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (a[i] > a[j]) {
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
I also think it's a kind of selection sort, but an inefficient one that does too many swaps. In a normal selection sort you find the smallest element and swap it into the first position, then find the next smallest and swap it into the second position, etc. In your sort you swap every time you find a smaller element than the one currently in the first position, etc. The effect is the same in that the smallest element is moved to the first position, then the second smallest to the second position, etc.
A more usual selection sort:
Code:
void selection_sort(int a[], int n) {
for (int i = 0; i < n - 1; i++) {
int k = i;
for (int j = i + 1; j < n; j++)
if (a[j] < a[k])
k = j;
int t = a[i];
a[i] = a[k];
a[k] = t;
}
}
Obviously selection_sort will be faster than mystery_sort since it implements essentially the same algorithm but does fewer swaps.