From aa3ecdd6346b40ab53bd04861ca42cd6de09ab38 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 17 Dec 2020 14:15:34 +0100 Subject: Fixing cpp08 span --- cpp08/ex01/span.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'cpp08/ex01/span.cpp') diff --git a/cpp08/ex01/span.cpp b/cpp08/ex01/span.cpp index ab17049..4bab0fc 100644 --- a/cpp08/ex01/span.cpp +++ b/cpp08/ex01/span.cpp @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/15 06:57:44 by charles #+# #+# */ -/* Updated: 2020/12/15 12:11:38 by cacharle ### ########.fr */ +/* Updated: 2020/12/17 14:12:43 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ Span::Span(Span const& other) m_under[i] = other.m_under[i]; } -void Span::operator=(Span const& other) +Span& Span::operator=(Span const& other) { delete [] m_under; m_size = other.m_size; @@ -32,6 +32,7 @@ void Span::operator=(Span const& other) m_fillIndex = other.m_fillIndex; for (unsigned int i = 0; i < m_fillIndex; i++) m_under[i] = other.m_under[i]; + return *this; } Span::~Span() { delete [] m_under; } @@ -50,7 +51,14 @@ void Span::addNumber(int x) int Span::shortestSpan() const { setupSpan(); - return m_under[1] - m_under[0]; + int shortest = m_under[m_fillIndex - 1] - m_under[0]; + for (size_t i = 0; i < m_fillIndex - 1; i++) + { + int span = m_under[i + 1] - m_under[i]; + if (span < shortest) + shortest = span; + } + return shortest; } int Span::longestSpan() const -- cgit