#include <stdlib.h>
#include <iostream>
using std::cout;
using std::endl;
#define N 10
#define M 100
#define SWAP(x,y) {int tmp=x; x=y; y=tmp;}
void print(int *a)
{
for(int i=0; i<N; ++i)
{
printf("%3d", a[i]);
}
printf("\n");
}
void selectSort(int *a)
{
for(int i=0; i<N-1; ++i)
{
int minPos = i;
for(int j=i+1; j<N; ++j)
{
if(a[minPos] > a[j])
{
minPos = j;
}
}
SWAP(a[minPos], a[i]);
}
}
int main()
{
srand(time(NULL));
int *a = (int*)malloc(sizeof(int)*N);
for(int i=0; i<N; ++i)
{
a[i] = rand() % M;
}
print(a);
selectSort(a);
print(a);
free(a);
return 0;
}