分别设计一个支持整型、实型、字符型的选择排序的函数模板 selectSort,以及一个打 印整型、实型、字符型数组的函数模板 printArray,在主程序调用。
要点写在注释内了
#include<iostream>
using namespace std;
template < typename T>
void selectSort(T a[ ], int n);//函数模板的声明包括着template
template < typename T>
void printArray(T a[ ], int n);//虚拟类型同样可以定义为T,你知道为什么吗?
int main()
{ int intarr[10]={20,18, 7, 19, 9, 8, 2, 12,10,1};
float floatarr[12]={9.1, 1.9, 8.2, 7.3, 6.4, 3.7, 5.5, 4.6, 2.8, 5.8, 4.6, 2.9};
char chararr[8]= {'C', 'd', 'e','x','B','D','A', 'a' };
selectSort(intarr,10);
cout << "the sorted float array:";
printArray(intarr,10);
selectSort(floatarr,12);
cout << "the sorted float array:";
printArray(floatarr,12);
selectSort(chararr,8);
cout << "the sorted float array:";
printArray(chararr,8);
return 0;
}
template < typename T>
void selectSort(T a