From 71f6ff89e721080c621524376758dc7dd9dcc2ae Mon Sep 17 00:00:00 2001 From: "Nastya (PozdiayevaAV)" Date: Fri, 31 Oct 2025 10:57:49 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=B8=D1=81=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 histogram.cpp diff --git a/histogram.cpp b/histogram.cpp new file mode 100644 index 0000000..d437f30 --- /dev/null +++ b/histogram.cpp @@ -0,0 +1,48 @@ +#include "histogram.h" +#include +#include +using namespace std; +void find_minmax( const vector& numbers, double& minN, double& maxN) { + minN = numbers[0]; + maxN = numbers[0]; + + for (double x: numbers){ + if (minN > x){ + minN = x; + } + if (maxN < x){ + maxN = x; + } + } + +} + +vector make_histogram(const vector& numbers, size_t bin_count){ + double minN, maxN; + find_minmax( numbers, minN, maxN); + + vector bins(bin_count); + double diff = (maxN - minN) / bin_count; + size_t max_count = 0; + for (size_t i = 0; i numbers[i])){ + bins[j]++; + if (bins[j] > max_count){ + max_count = bins[j]; + } + found = true; + } + } + if(!found){ + bins[bin_count - 1]++; + if (bins[bin_count - 1] > max_count){ + max_count = bins[bin_count - 1]; + } + } +} +return bins; +}