#include <iostream>
#include <cstdlib>
using namespace std;
/*
* name : selection sort
* author : sangoly
* O(n^2)
* S(1)
* date : 2014/4/15
*/
void selection_sort(int a[], int length)
{
for (int i=0; i<length-1; i++) {
int smallest = i;
for (int j=i+1; j<length; j++)
if (a[j] < a[smallest]) {
int tmp = a[smallest];
a[smallest] = a[j];
a[j] = tmp;
}
}
}
int main(int argc, const char **argv)
{
int a[] = {3, 41, 52, 26, 38, 57, 9, 49};
selection_sort(a, 8);
for (int i=0; i<8; i++)
cout<<a[i]<<" ";
cout<<endl;
system("pause");
return 0;
}