From 59b6fa5051eb2e7af3cb3cb649a45b9bc331acbb Mon Sep 17 00:00:00 2001 From: u115-03 Date: Mon, 7 Oct 2024 13:39:00 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histogram.cpp | 21 +++++++++++++-------- histogram_internal.h | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index 344f24d..d7e5196 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -5,14 +5,19 @@ 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; - } - else if (x > max) { - max = x; + if (numbers.size() == 0){ + min = 0; + max = 0; + } else { + min = numbers[0]; + max = numbers[0]; + for (double x : numbers) { + if (x < min) { + min = x; + } + else if (x > max) { + max = x; + } } } } diff --git a/histogram_internal.h b/histogram_internal.h index 3ea054e..630e711 100644 --- a/histogram_internal.h +++ b/histogram_internal.h @@ -3,6 +3,6 @@ #include -void find_minmax(const std::vector &numbers, double &min, double &max) +void find_minmax(const std::vector &numbers, double &min, double &max); #endif // HISTOGRAM_INTERNAL_H_INCLUDED