选择排序
#include <stdio.h>
void select_sort(int* arr, int len)
{
int max_i=0;
int a;
for(int i=0; i<len-1; i++)
{
for(int j=i; j<len; j++)
{
if(arr[j] > arr[max_i])
{
max_i = j;
}
}
a=arr[i];
arr[i] = arr[max_i];
arr[max_i] = a;
max_i = i+1;
}
}
int main()
{
int arr[] = {5, 3, 8, 6, 2, 7, 1, 4};
int len = sizeof(arr)/sizeof(arr[0]);
select_sort(arr, len);
for(int i=0; i<len; i++)
{
printf("%d ", arr[i]);
}
return 0;
}