You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
441 B

#include <bits/stdc++.h>
using namespace std;
//选择排序
int a[] = {4, 1, 9, 5, 1, 7, 2};
int main() {
// C++求整数数组长度的办法
int len = sizeof(a) / 4;
for (int i = 0; i < len - 1; i++) {
int mi = i;
for (int j = i + 1; j < len; j++)
if (a[j] < a[mi]) mi = j;
swap(a[i], a[mi]);
}
for (int i = 0; i < len; i++) cout << a[i] << " ";
return 0;
}