- wangjiahong 的博客
选择排序
- @ 2025-10-25 14:30:25
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int max;
int a[10]={1,3,2,8,4,5,7,11,9,10};
for(int i=0;i<10;i++){
max=i;
for(int j=i;j<10;j++){
if(a[j]>a[max])
max=j;
}
swap(a[i],a[max]);
}
for(int i=0;i<10;i++)
cout<<a[i]<<' ';
return 0;
}