#include <iostream>
// #include <string>
#include <cstring>using namespace std;// 冒泡排序:函数模板
template<typename T>
void mySort(T arr[], int len){ // size参数是数组的个数,一定是int型的for (size_t i = 0; i < len -1; i++){for(size_t j = 0; j < len - i - 1; j++){if(arr[j] > arr[j+1]){T temp = arr[j + 1];arr[j + 1] = arr[j];arr[j] = temp;}}}
}// 打印结果函数
template<typename T>
void printArr(T arr[], int len){for(size_t i = 0; i < len; i++){cout << arr[i] << " ";}cout << endl;} int main()
{char tempChar[] = "abzab";int charLen = strlen(tempChar);mySort(tempChar, charLen);printArr(tempChar, charLen);int tempInt[] = {4,33,11,2,7};int intLen = sizeof(tempInt) / sizeof(tempInt[0]);mySort(tempInt,intLen);printArr(tempInt,intLen);return 0;
}