#include "histogram.h" bool find_minmax(const std::vector& numbers, double& min, double& max) { if (numbers.size() == 0){ return true; } else{ min = numbers[0]; max = numbers[0]; for (double x : numbers) { if (x < min) { min = x; } else if (x > max) { max = x; } } return false; } } std::vector make_histogram(const std::vector& numbers, size_t bin_count){ double max,min; std::vector bins(bin_count); find_minmax(numbers,min,max); double bin_size = (max - min) / bin_count; for(double x:numbers) { bool found = false; for (size_t j = 0; (j < bin_count - 1) && !found; j++) { auto lo = min + j * bin_size; auto hi = min + (j + 1) * bin_size; if ((lo <= x) && (x < hi)) { bins[j]++; found = true; } } if (!found) bins[bin_count-1]++; } return bins; }