编写一个函数模板使用冒泡排序将一维数组内容按升序排列并打印出来写出调用此函数模板的完整程序使得函数调用时数组类型可以是整形或者双精度类型。要求:能在主函数中完成如下int类型数组和double类型数组的排序int mainint iArray=619577158023101082;double dArray=051125255652575;return 0;2排序函数模板声明如下:void bub
#include
template
int main() { int iArray[] = {6, 19, 5, 77, 15, 80, 23, 10, 108, 2}; double dArray[] = {0.5, 112.5, 25.5, 6.5, 2.5, 7.5}; int iSize1 = sizeof(iArray) / sizeof(int); int iSize2 = sizeof(dArray) / sizeof(double);
cout<<"排序前的int类型数组:"<<endl;
for(int i = 0; i < iSize1; i++)
cout<<iArray[i]<<" ";
cout<<endl;
cout<<"排序后的int类型数组:"<<endl;
bubble_sort(iArray, iSize1);
cout<<"排序前的double类型数组:"<<endl;
for(int i = 0; i < iSize2; i++)
cout<<dArray[i]<<" ";
cout<<endl;
cout<<"排序后的double类型数组:"<<endl;
bubble_sort(dArray, iSize2);
return 0;
原文地址: https://www.cveoy.top/t/topic/hoWB 著作权归作者所有。请勿转载和采集!