#include <stdio.h>
int cmp(int x, int y) // compare x with y
{
return x < y; // 1 if x < y, 0 otherwise
}
 void swap(int *x, int *y)
 {
 int tmp = *x;

 *x = *y;
 *y = tmp;
 }

 size_t select(int p[], size_t len)
 {
 size_t pos = 0; // position of the highest-precedence element
for (size_t i = 0; i < len; ++i) {
if (cmp(p[i], p[pos])) {
pos = i;
}
}
 return pos;
}
void disp(int p[], size_t len) {
      for (size_t i = 0; i < len; ++i) {
      printf("%d ", p[i]);
      }
      printf("\n");
      }
int main(void)
{
int a[] = {3, 1, 4, 1, 5, 9, 2, 6, 5}; // array to be sorted
size_t n = sizeof a / sizeof a[0]; // number of elements
        for (size_t i = 0; i < n - 1; ++i) {
        size_t j = i + 1 + select(a+i+1,n-i-1);
            if (cmp( a[j], a[i] )) {
            swap( &a[j] , &a[i]);
            }
        }
disp(a, n);
return 0;
}