Files
python/TangDou/LuoGuBook/L9_2_Select.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

19 lines
441 B
C++

#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;
}