#include #include #include "histogram.h" using namespace std; void find_minmax(const vector& numbers, double& min, double& max) { min = numbers[0]; max = numbers[0]; for (double x : numbers) { if (x < min) { min = x; } if (x > max) { max = x; } } } //создание гистограммы vector make_histogram(const vector& numbers, size_t bin_count) { double min, max; find_minmax(numbers, min, max); double bin_size = (max - min) / bin_count; vector bins(bin_count, 0); for (double number : numbers) { size_t bin_index = static_cast((number - min) / bin_size); if (bin_index >= bin_count) { bin_index = bin_count - 1; } bins[bin_index]++; } return bins; }