//SelectSort //选择最小的,交换到左边 #include<iostream> using namespace std; void SelectSort (int a[],int n) { for(int i=0;i<n;i++) { int min =i;//记录最小的值 for(int j=i+1;j<n;j++) { if(a[j]<a[min]) { min=j; } } swap(a[i],a[min]); } } int main() { int x[]={1,3,5,7,9,0,2,4,6,8}; SelectSort(x,10); for(int i=0;i<10;i++) { cout<<x[i]<<" "; cout<<endl; } return 0; }
原文:https://www.cnblogs.com/chuxinbubian/p/11306449.html