diff options
Diffstat (limited to 'cpp08/ex02/main.cpp')
| -rw-r--r-- | cpp08/ex02/main.cpp | 195 |
1 files changed, 177 insertions, 18 deletions
diff --git a/cpp08/ex02/main.cpp b/cpp08/ex02/main.cpp index cb138b3..a9f0995 100644 --- a/cpp08/ex02/main.cpp +++ b/cpp08/ex02/main.cpp @@ -6,37 +6,196 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/15 07:30:43 by charles #+# #+# */ -/* Updated: 2020/12/15 14:24:54 by cacharle ### ########.fr */ +/* Updated: 2020/12/17 11:22:07 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include <iostream> +#include <list> #include "mutantstack.hpp" int main() { { std::cout << "=================== SUBJECT MAIN ======================" << std::endl; - MutantStack<int> mstack; - mstack.push(5); - mstack.push(17); - std::cout << mstack.top() << std::endl; - mstack.pop(); - std::cout << mstack.size() << std::endl; - mstack.push(3); - mstack.push(5); - mstack.push(737); - mstack.push(0); - MutantStack<int>::iterator it = mstack.begin(); - MutantStack<int>::iterator ite = mstack.end(); - ++it; - --it; - while (it != ite) { - std::cout << *it << std::endl; + MutantStack<int> mstack; + mstack.push(5); + mstack.push(17); + std::cout << mstack.top() << std::endl; + mstack.pop(); + std::cout << mstack.size() << std::endl; + mstack.push(3); + mstack.push(5); + mstack.push(737); + mstack.push(0); + MutantStack<int>::iterator it = mstack.begin(); + MutantStack<int>::iterator ite = mstack.end(); ++it; + --it; + while (it != ite) + { + std::cout << *it << std::endl; + ++it; + } + std::stack<int> s(mstack); + } + std::cout << "-----------------------------------------------------" << std::endl; + { + std::list<int> mstack; + mstack.push_back(5); + mstack.push_back(17); + std::cout << mstack.back() << std::endl; + mstack.pop_back(); + std::cout << mstack.size() << std::endl; + mstack.push_back(3); + mstack.push_back(5); + mstack.push_back(737); + mstack.push_back(0); + std::list<int>::iterator it = mstack.begin(); + std::list<int>::iterator ite = mstack.end(); + ++it; + --it; + while (it != ite) + { + std::cout << *it << std::endl; + ++it; + } + std::list<int> s(mstack); } - std::stack<int> s(mstack); } + + std::cout << std::endl; + + { + std::cout << "=================== METHODS ======================" << std::endl; + + std::cout << "------------------- DEFAULT CONSTRUCTOR" << std::endl; + MutantStack<int> a; + std::cout << a.empty() << std::endl; + std::cout << a.size() << std::endl; + a.push(1); + a.push(2); + a.push(3); + std::cout << a.empty() << std::endl; + std::cout << a.size() << std::endl; + std::cout << a.top() << std::endl; + + std::cout << "------------------- COPY CONSTRUCTOR" << std::endl; + MutantStack<int> b(a); + std::cout << b.empty() << std::endl; + std::cout << b.size() << std::endl; + std::cout << b.top() << std::endl; + b.push(4); + std::cout << b.top() << std::endl; + std::cout << a.top() << std::endl; + + std::cout << "------------------- ASSIGN" << std::endl; + MutantStack<int> c; + c.push(-1); + c = a; + std::cout << c.empty() << std::endl; + std::cout << c.size() << std::endl; + std::cout << c.top() << std::endl; + c.push(4); + std::cout << c.top() << std::endl; + std::cout << a.top() << std::endl; + + std::cout << "------------------- POP" << std::endl; + a.pop(); + a.pop(); + std::cout << a.empty() << std::endl; + std::cout << a.size() << std::endl; + std::cout << a.top() << std::endl; + std::cout << "------------------- COMPARISON" << std::endl; + std::cout << (a == b) << std::endl; + std::cout << (a != c) << std::endl; + std::cout << (a < c ) << std::endl; + std::cout << (a > c ) << std::endl; + std::cout << (a <= c) << std::endl; + std::cout << (a >= c) << std::endl; + } + + std::cout << std::endl; + + { + std::cout << "=================== ITERATOR ======================" << std::endl; + MutantStack<float> a; + a.push(1.1f); + a.push(2.2f); + a.push(3.3f); + + std::cout << "------------------- PRE INCREMENT" << std::endl; + for (MutantStack<float>::iterator it = a.begin(); it != a.end(); ++it) + std::cout << *it << std::endl; + + std::cout << "------------------- POST INCREMENT" << std::endl; + for (MutantStack<float>::iterator it = a.begin(); it != a.end(); it++) + std::cout << *it << std::endl; + + std::cout << "------------------- PRE DECREMENT" << std::endl; + for (MutantStack<float>::iterator it = --a.end(); it != a.begin(); --it) + std::cout << *it << std::endl; + + std::cout << "------------------- POST DECREMENT" << std::endl; + for (MutantStack<float>::iterator it = --a.end(); it != a.begin(); it--) + std::cout << *it << std::endl; + + std::cout << "------------------- ARROW OPERATOR" << std::endl; + MutantStack<float>::iterator it_arrow = a.begin(); + std::cout << it_arrow.operator->() << std::endl; + std::cout << *(it_arrow.operator->()) << std::endl; + + std::cout << "------------------- PRE INCREMENT / DEREF" << std::endl; + for (MutantStack<float>::iterator it = a.begin(); it != --a.end();) + std::cout << (*++it) << std::endl; + + std::cout << "------------------- POST INCREMENT / DEREF" << std::endl; + for (MutantStack<float>::iterator it = a.begin(); it != --a.end();) + std::cout << *it++ << std::endl; + + std::cout << "------------------- COMPARISON" << std::endl; + std::cout << (a.begin() == a.end()) << std::endl; + std::cout << (a.begin() != a.end()) << std::endl; + + std::cout << "------------------- COPY CONSTRUCTOR" << std::endl; + MutantStack<float>::iterator it_copied = ++a.begin(); + MutantStack<float>::iterator it_copy(it_copied); + std::cout << *it_copied << std::endl; + std::cout << *it_copy << std::endl; + + std::cout << "------------------- ASSIGNMENT" << std::endl; + MutantStack<float>::iterator it_assign(a.begin()); + it_assign = it_copied; + std::cout << *it_copied << std::endl; + std::cout << *it_assign << std::endl; + + std::cout << "------------------- ITERATOR ASSIGN" << std::endl; + for (MutantStack<float>::iterator it = a.begin(); it != a.end(); ++it) + *it = 4.4f; + for (MutantStack<float>::iterator it = a.begin(); it != a.end(); ++it) + std::cout << *it << std::endl; + + std::cout << "------------------- MORE" << std::endl; + MutantStack<float> d; + d.push(0.5f); + d.push(1.5f); + d.push(2.5f); + d.push(3.5f); + d.push(4.5f); + d.push(5.5f); + d.push(6.5f); + d.push(7.5f); + d.push(8.5f); + d.push(9.5f); + d.push(1.9f); + for (MutantStack<float>::iterator it = d.begin(); it != d.end(); ++it) + std::cout << *it << std::endl; + + std::cout << "------------------- REVERSE" << std::endl; + for (MutantStack<float>::reverse_iterator it = d.rbegin(); it != d.rend(); ++it) + std::cout << *it << std::endl; + } + return 0; } |
