Commit 3b896cce authored by Thiago Santini's avatar Thiago Santini

Adds mean and makes median more generic

parent 04aa48b5
......@@ -100,12 +100,17 @@ void set(const QSettings* settings, const QString key, T& v)
void loadSoundEffect(const QString& fileName, const QString& exeDir, QSoundEffect& effect);
template <typename T>
double median(std::vector<T> v)
double median(T v)
{
int size = static_cast<int>(v.size());
std::sort(v.begin(), v.end());
int mid = size / 2;
return size % 2 == 0 ? (v[mid] + v[mid - 1]) / 2 : v[mid];
size_t mid = v.size() / 2;
return v.size() % 2 == 0 ? (v[mid] + v[mid - 1]) / 2 : v[mid];
}
template <typename T>
double mean(T v)
{
return std::accumulate(v.begin(), v.end(), 0.0) / v.size();
}
template <typename T>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment