选择排序?
#include
#include
using namespace std;
template
void selectsort(T A[], size_t const n){
for (size_t i = 0; i != (n - 1); ++i){
size_t small = i;
for (size_t j = i + 1; j != n; ++j){
if (A[j] < A[small]) small = j;
}
swap(A[i], A[small]);
}
}
int main(){
size_t const N = 10;
int A[N] = { 78, 234, 25, 47, 2, 3, 54, 125, 6, 9 };
selectsort(A, N);
for (size_t i = 0; i != N; ++i){
cout << A[i] << " ";
}
cout << "\n";
return 0;
}
亲,函数不是这样用的,数组也不是这样输出的,感觉你基础都没学好呢