From d5f702afa3bf812c57f84d599fbd9f574d288e92 Mon Sep 17 00:00:00 2001 From: "PARZIVAL (BreganIM)" Date: Thu, 8 May 2025 17:29:12 +0300 Subject: [PATCH] =?UTF-8?q?upd:=D0=9A=D0=BE=D0=B4=20=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B0=D1=87=D0=B5=D0=BD=20=D0=B4=D0=BE=20=D0=BC=D0=BE=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) 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; -}