C++ 函数模板实现冒泡排序:排序整形和双精度数组
#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/oRMI 著作权归作者所有。请勿转载和采集!