酷代码 AI
菜单
服务商

C++实现优化选择排序对输入数字从大到小排序

```cpp #include <iostream> using namespace std; // 优化后的选择排序函数,从大到小排序 void optimizedSelectionSort(int arr[], int n) { for (int i = 0; i < n - 1; i++) { int maxIndex = i; for (int j = i + 1; j < n; j++) { if (arr[j] > arr[maxIndex]) { maxIndex = j; } } if (maxIndex != i) { swap(arr[i], arr[maxIndex]); } } } int main() { int n; cin >> n; int arr[100]; for (int i = 0; i < n; i++) { cin >> arr[i]; } optimizedSelectionSort(arr, n); for (int i = 0; i < n; i++) { cout << arr[i]; if (i < n - 1) { cout << " "; } } return 0; } ``` ######[AI问答 | 280点数解答 | 2026-02-25 22:25:19]

相关提问
发财导航,免费问AI
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]