选择排序 - c++实现
作者:互联网
选择排序
#include<iostream>
#include<vector>
using namespace std;
void selectionSort(vector<int> &arr){
for(int i = 0; i < arr.size() - 1; ++i){
int min_index = i;
for(int j = i + 1; j < arr.size(); ++j){
if(arr[j] < arr[min_index])
min_index = j;
}
swap(arr[i], arr[min_index]);
}
}
int main(){
vector<int> arr{10, 9, 7, 8, 6, 5, 2, 4, 3, 1};
selectionSort(arr);
for(auto each : arr)
cout << each << " ";
cout << endl;
return 0;
}
标签:index,arr,min,int,selectionSort,c++,选择,排序,size 来源: https://blog.csdn.net/fengyuesong/article/details/120888408