//选择排序--简单选择排序
void selection_print_list(int list[] , int count)
{
for(int i = 0 ; i < count ; i++)
{
printf("%5d" , list[i]);
}
printf("\n");
}
//交换
void selection_swap_data(int *a , int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void selection_sort(int list[] , int count)
{
for(int i = 0 ; i < count - 1 ; i++)
{
int index = i;
for(int j = i + 1; j < count ; j++)
{
if(list[j] < list[index])
{
index = j;
}
}
if (index > i)
{
selection_swap_data(&list[index] , &list[i]);
}
}
}
void selection_sort_main()
{
int list[] = {8,7,9,3,6,2,4,1,5};
selection_print_list(list , 9);
selection_sort(list , 9);
selection_print_list(list , 9);
return;
}