代码
#include <stdio.h>
void SelectSort(int arr[], int size)
{
int i, j, min, temp;
for (i = 0; i < size - 1; ++i) {
min = i;
for (j = i + 1; j < size; ++j) {
if (arr[j] < arr[min]) {
min = j;
}
}
temp = arr[min];
arr[min] = arr[i];
arr[i] = temp;
}
}
void PrintArr(int arr[], int size)
{
for (int i = 0; i < size; ++i) {
printf("%d ", arr[i]);
}
printf("\r\n");
}
int main()
{
int arr[10] = {6, 0, 5, 3, 15, 21, 13, 9, 12, 8};
PrintArr(arr, 10);
SelectSort(arr, 10);
PrintArr(arr, 10);
return 0;
}
原文:https://www.cnblogs.com/causewang/p/12057004.html