diff --git a/math/stats/Median.h b/math/stats/Median.h index 488f6ac..20d874c 100644 --- a/math/stats/Median.h +++ b/math/stats/Median.h @@ -30,17 +30,18 @@ namespace Stats { /** add the given scalar value to the median calculation */ void add(const Scalar value) { - const auto idx = std::upper_bound( sorted.begin(), sorted.end(), value ); - sorted.insert( idx, value ); + sorted.push_back(value); } - + /** get the median of all added values */ - Scalar get() const { + Scalar get() { // sanity check Assert::isNot0(sorted.size(), "add elements first!"); + std::sort(sorted.begin(), sorted.end()); + if (sorted.size() % 2 == 1) { // odd const int idx = sorted.size()/2;