diff --git a/histogram.cpp b/histogram.cpp index fe12cab..6a509c2 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -1,13 +1,13 @@ - #include "histogram.h" #include "histogram_internal.h" +#include #include - using namespace std; bool find_minmax(const vector& numbers, double& min, double& max) { - if (numbers.empty()) + if (numbers.empty()) { return false; + } min = numbers[0]; max = numbers[0]; for (double x : numbers) { @@ -16,7 +16,7 @@ bool find_minmax(const vector& numbers, double& min, double& max) { if (x > max) max = x; } - return true; + return false; } vector make_histogram(const vector& numbers, size_t bin_count) { @@ -27,6 +27,7 @@ vector make_histogram(const vector& numbers, size_t bin_count) { for (size_t i = 0; i < numbers.size(); i++) { bool found = false; + for (size_t j = 0; j < bin_count - 1 && !found; j++) { double lo = min + j * bin_size; double hi = min + (j + 1) * bin_size; @@ -35,15 +36,9 @@ vector make_histogram(const vector& numbers, size_t bin_count) { found = true; } } + if (!found) bins[bin_count - 1]++; } return bins; } - -double compute_bin_size(const std::vector& numbers, size_t bin_count) { - double min, max; - if (!find_minmax(numbers, min, max)) - return 0.0; - return (max - min) / bin_count; -}