#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
void swap(int *a,int i,int j)
{
int temp = a[i];
a[i] = a[j];
a[j] = temp;
};
void SelectSort(int *a, int n)
{
int i,j;
int min;
for(i=0;i<n-1;i++)
{
min = i;
for(j=i+1;j<n;j++)
{
if(a[j] < a[min])
{
min = j;
}
}
if(min != i)
{
swap(a,i,min);
}
}
};
int main()
{
int i = 0;
int a[13] = {5,4,9,8,7,6,3,0,1,2,15,24,100};
SelectSort(a,13);
for(;i<13;i++)
{
printf("%d ",a[i]);
}
printf("\n");
system("pause");
return 0;
}本文出自 “年少輕狂” 博客,請務必保留此出處http://shpshao.blog.51cto.com/1931202/1297434