#include <stdio.h>
// 选择排序
void selectSort(int arr[], int len){
int temp;
for (int i = 0; i < len - 1; i++) {
for (int j = i+1; j < len; j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
int main(int argc, const char * argv[]) {
int a[7] = {9,6,4,3,0,1,5};
// 排序前
for (int i = 0; i < 7; i++) {
printf("%d ", a[i]);
}
printf("
");
selectSort(a, 7);
// 排序后
for (int i = 0; i < 7; i++) {
printf("%d ", a[i]);
}
printf("
");
return 0;
}
效果图: