diff --git a/d08/ex00/easyfind b/d08/ex00/easyfind deleted file mode 100755 index c5468ea..0000000 Binary files a/d08/ex00/easyfind and /dev/null differ diff --git a/d08/ex01/Span.cpp b/d08/ex01/Span.cpp index 28a564b..3f32821 100644 --- a/d08/ex01/Span.cpp +++ b/d08/ex01/Span.cpp @@ -68,7 +68,7 @@ bool Span::empty() const { * PUBLIC MEMBER FUNCTIONS *********************************************/ -void Span::addNumber(int nb) { +void Span::addNumber(int nb) { if (_container.size() >= _max) throw std::out_of_range(B_RED "out of range number" RESET); _container.push_back(nb); @@ -98,8 +98,6 @@ void Span::addNumber(InputIterator first, InputIterator last) { } template void Span::addNumber(int*, int*); - - unsigned int Span::shortestSpan() { int const size = _container.size(); unsigned int shortest = longestSpan(); @@ -123,9 +121,3 @@ unsigned int Span::longestSpan() { return (_sort.back() - _sort.front()); } -/********************************************* - * NESTED CLASS - *********************************************/ - -//void Span::Class::function() {} - diff --git a/d08/ex01/Span.hpp b/d08/ex01/Span.hpp index b6de956..0a090ac 100644 --- a/d08/ex01/Span.hpp +++ b/d08/ex01/Span.hpp @@ -17,9 +17,9 @@ public: Span & operator=( Span const & rhs ); void addNumber(int nb); -// void addNumber(int * arr, unsigned int size); template void addNumber(InputIterator first, InputIterator last); +// void addNumber(int * arr, unsigned int size); unsigned int shortestSpan(); unsigned int longestSpan(); diff --git a/d08/ex01/main.cpp b/d08/ex01/main.cpp index d3b6abd..47bb891 100644 --- a/d08/ex01/main.cpp +++ b/d08/ex01/main.cpp @@ -1,6 +1,7 @@ #include #include #include "colors.h" +#include // rand #include "Span.hpp" diff --git a/d08/ex02/Makefile b/d08/ex02/Makefile index 1715a65..32e28a8 100644 --- a/d08/ex02/Makefile +++ b/d08/ex02/Makefile @@ -32,9 +32,8 @@ D_SRCS = . SRCS = main.cpp D_HEADERS = . -HEADERS = -#HEADERS = colors.h \ -# MutantStack.hpp +HEADERS = colors.h \ + MutantStack.hpp D_OBJS = builds OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) diff --git a/d08/ex02/MutantStack.hpp b/d08/ex02/MutantStack.hpp index e0c2eaf..201dae8 100644 --- a/d08/ex02/MutantStack.hpp +++ b/d08/ex02/MutantStack.hpp @@ -7,22 +7,24 @@ template class MutantStack : public std::stack { public: + /* typedef T * iterator; typedef T const * const_iterator; iterator begin() {return (&this->top() - (this->size() - 1));} - iterator end() {return (&this->top()+ 1);} + iterator end() {return (&this->top() + 1);} + const_iterator begin() const {return (&this->top() - (this->size() - 1));} - const_iterator end() const {return (&this->top()+ 1);} + const_iterator end() const {return (&this->top() + 1);} + */ -// typedef typename std::stack::container_type::iterator iterator; -// typedef typename std::stack::container_type::const_iterator const_iterator; - -// iterator begin() {return this->c.begin();} -// iterator end() {return this->c.end();} -// const_iterator begin() const {return this->c.begin();} -// const_iterator end() const {return this->c.end();} + typedef typename std::stack::container_type::iterator iterator; + typedef typename std::stack::container_type::const_iterator const_iterator; + iterator begin() {return this->c.begin();} + iterator end() {return this->c.end();} + const_iterator begin() const {return this->c.begin();} + const_iterator end() const {return this->c.end();} }; #endif diff --git a/d08/ex02/main.cpp b/d08/ex02/main.cpp index fcaae06..e089785 100644 --- a/d08/ex02/main.cpp +++ b/d08/ex02/main.cpp @@ -1,11 +1,13 @@ #include #include "colors.h" #include "MutantStack.hpp" +#include // rand -#define N_TEST "2" +#define N_TEST "3" int main() { int i = 0; + srand(time(NULL)); std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] " << "test simple iterator :" RESET "\n"; @@ -26,6 +28,100 @@ int main() { std::cout << *it << "\n"; } + std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] " + << "test stack size 128:" RESET "\n"; + { + MutantStack mstack; + + mstack.push(-42); + for (unsigned int i = 0; i < 126; i++) + mstack.push(rand() % 10000000000000); + mstack.push(42); + + MutantStack::iterator it = mstack.begin(); + MutantStack::iterator ite = mstack.end(); + + std::cout << "[ "; + for (; it != ite; it++) + std::cout << *it << " "; + std::cout << "]\n"; + + it = mstack.begin(); + ite = mstack.end(); + + std::cout << B_BLUE "firtst and last :" RESET "\n"; + std::cout << *it << " | " << *(ite - 1) << "\n\n"; + } + + std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] " + << "test stack size 129:" RESET "\n"; + { + MutantStack mstack; + + mstack.push(-42); + for (unsigned int i = 0; i < 127; i++) + mstack.push(rand() % 10000000000000); + mstack.push(42); + + MutantStack::iterator it = mstack.begin(); + MutantStack::iterator ite = mstack.end(); + + std::cout << "[ "; + for (; it != ite; it++) + std::cout << *it << " "; + std::cout << "]\n"; + + it = mstack.begin(); + ite = mstack.end(); + + std::cout << B_BLUE "firtst and last :" RESET "\n"; + std::cout << *it << " | " << *(ite - 1) << "\n\n"; + } + + std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] " + << "test stack size 10000:" RESET "\n"; + { + MutantStack mstack; + + mstack.push(-42); + for (unsigned int i = 0; i < 10000; i++) + mstack.push(rand() % 10000000000000); + mstack.push(42); + + MutantStack::iterator it = mstack.begin(); + MutantStack::iterator ite = mstack.end(); + + std::cout << "[ "; + for (; it != ite; it++) + std::cout << *it << " "; + std::cout << "]\n"; + + it = mstack.begin(); + ite = mstack.end(); + + std::cout << B_BLUE "firtst and last :" RESET "\n"; + std::cout << *it << " | " << *(ite - 1) << "\n\n"; + } + + std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] " + << "test const iterator :" RESET "\n"; + { + MutantStack mstack; + + mstack.push(7); + mstack.push(987); + mstack.push(9); + mstack.push(8); + mstack.push(34); + mstack.push(1); + + MutantStack::const_iterator it = mstack.begin(); + MutantStack::const_iterator ite = mstack.end(); + + for (; it != ite; it++) + std::cout << *it << "\n"; + } + std::cout << B_YELLOW "\n[" << ++i << "/" N_TEST "] " << "tests subject :" RESET "\n"; {