简单选择排序算法(C++版)

时间:2021-11-22 23:58:46
#include <iostream>

using namespace std;

/** Simple Select Sort
* brief:
* Key:
* * position: the max index
* * trip: Begin and End(:n-i)
* * swap
*
*/ template <typename T>
void simpleSelect(T* a, int n) {
T max;
int pos;
for (int i = ; i < n; i++) {
max = a[];
pos = ;
for(int j =; j < n-i; j ++) {
if(max < a[j]) {
max = a[j];
pos = j;
}
}
swap(a[pos], a[n-i-]);
}
}