请实现一个模板函数,求出数组中的中位数,数组可能为整数数组,也可能为浮点数数组。数组的中位数定义为数组按非递减顺序排序后的第 ⌊ n/2 ⌋ + 1 个数,其中n为数组元素个数。每个测试用例都会测试一个整数数组和一个浮点数数组。
输入描述
每个测例共 3 行,第一行输入 m 和 n ( m > 0, n > 0 ),分别表示接下来有 m 个整数和 n 个浮点数。第二行为 m 个整数,用空格隔开,第三行为 n 个浮点数,用空格隔开。整数的范围不超过 int 可表示范围,浮点数的范围不超过 double 可表示的范围。
输出描述
对于每一个测例,输出两行,第一行为m个整数的中位数,第二行为n个浮点数的中位数。
示例1:
输入:4 5
1 2 3 4
10.01 0.003 255.256 -3.2 100000.3
输出:3
10.01
#include <iostream>
#include<algorithm>
#include<cmath>
#include <cassert>
using namespace std;
/*
template <class T>
void outputmedian(T array, int count)
{
insertionSort(array, count);
T median;
int k=floor(count / 2);
median = array[k+1];
cout << median << endl;
}
*/
template &

最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



