我想计算存储在向量中的元素的中位数
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
....
....
....
vector<int> trmVa;
int size;
int median;
int trimVal;
trmVa.push_back(trimVal);
size = trmVa.size();
sort(trmVa.begin(), trmVa.end()); //I am having troubles here!!!!
if(size % 2) {
median = (trmVa[size/2 - 1] + trmVa[size/2]) /2;
printf("Module %d \n\n \t Median = %d\n", mod, median);
}else {
median = trimVa[size/2];
printf("Module %d \n\n \t Median = %d\n", mod, median);
}
错误:运算符 - 未为向量 >::iterator algo.h:722 定义。我很感激帮助。