diff --git a/ex01/Span.cpp b/ex01/Span.cpp new file mode 100644 index 0000000..65aa2d2 --- /dev/null +++ b/ex01/Span.cpp @@ -0,0 +1,44 @@ +#include "Span.hpp" +#include + +Span::Span() +{} + +Span::Span(unsigned int N): + _size(N) +{ +} + +Span::Span(const Span& src) +{ + *this = src; +} + +Span::~Span() +{ +} + +Span& Span::operator=(const Span& src) +{ + this->_size = src._size; + this->_vector = src._vector; + return *this; +} + +int Span::shortestSpan() const +{ + return *std::min_element(_vector.begin(), _vector.end()); +} + +int Span::longestSpan() const +{ + return *std::max_element(_vector.begin(), _vector.end()); +} + +void Span::addNumber(const int nb) +{ + if (this->_vector.size() == this->_size) + throw std::exception(); + this->_vector[this->_size] = nb; + this->_size++; +} \ No newline at end of file diff --git a/ex01/Span.hpp b/ex01/Span.hpp new file mode 100644 index 0000000..78e71f8 --- /dev/null +++ b/ex01/Span.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include + +class Span +{ + private: + unsigned int _size; + std::vector _vector; + + Span(); + + public: + Span(unsigned int N); + Span(const Span& src); + ~Span(); + + Span& operator=(const Span& src); + + int shortestSpan() const; + int longestSpan() const; + void addNumber(const int nb); +}; \ No newline at end of file