aboutsummaryrefslogtreecommitdiff
path: root/cpp08/ex01/span.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp08/ex01/span.cpp')
-rw-r--r--cpp08/ex01/span.cpp14
1 files changed, 11 insertions, 3 deletions
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 <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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