#include <iostream>
using namespace std;
//模板的小案例:
//利用模板实现char和int的数组排序;
//排序规则,从大到小,利用选择排序;
template<class T>
void mySwap(T &a, T &b)
{
T temp;
temp = a;
a = b;
b = temp;
}
template<class T>
void Qsort(T arry[],int len)
{
int i = 0, j = 0;
int min = i;
int temp = 0;
for (i; i < len; i++) {
min = i;
for (j = i + 1; j < len; j++) {
if (arry[j] <= arry[min]) {
min = j;
}
}
if (i != min) {
mySwap(arry[i], arry[min]);
}
}
}
void test01()
{
int arry[] = {435,56,57,678,78,8,989,90,90,56,34,56,67,78,23};
Qsort<int>(arry,sizeof(arry)/sizeof(int));
for (auto t : arry) {
cout << t << endl;
}
char charArry[] = { "hello" };
Qsort<char>(charArry, 5);
for (auto t : charArry) {
cout << t << endl;
}
}
int main()
{
test01();
return 0;
}