89 lines
1.8 KiB
C++
89 lines
1.8 KiB
C++
#include "MutantStack.hpp"
|
|
#include <iostream>
|
|
#include <list>
|
|
|
|
int main()
|
|
{
|
|
{
|
|
std::cout << "control tests with a list:" << std::endl;
|
|
std::list<int> mlist;
|
|
mlist.push_back(5);
|
|
mlist.push_back(17);
|
|
std::cout << mlist.back() << std::endl;
|
|
mlist.pop_back();
|
|
std::cout << mlist.size() << std::endl;
|
|
mlist.push_back(3);
|
|
mlist.push_back(5);
|
|
mlist.push_back(727);
|
|
mlist.push_back(0);
|
|
|
|
std::list<int>::iterator it = mlist.begin();
|
|
std::list<int>::iterator ite = mlist.end();
|
|
++it;
|
|
--it;
|
|
while (it != ite)
|
|
{
|
|
std::cout << *it << std::endl;
|
|
++it;
|
|
}
|
|
}
|
|
std::cout << std::endl;
|
|
|
|
{
|
|
std::cout << "basic iterator tests:" << 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(727);
|
|
mstack.push(0);
|
|
|
|
MutantStack<int>::iterator it = mstack.begin();
|
|
MutantStack<int>::iterator ite = mstack.end();
|
|
++it;
|
|
--it;
|
|
//*it = 20; // not a constant iterator, should be working if uncommented
|
|
while (it != ite)
|
|
{
|
|
std::cout << *it << std::endl;
|
|
++it;
|
|
}
|
|
std::stack<int> s(mstack);
|
|
}
|
|
std::cout << std::endl;
|
|
|
|
{
|
|
std::cout << "const iterator tests:" << 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(727);
|
|
mstack.push(0);
|
|
|
|
MutantStack<int>::const_iterator it = mstack.begin();
|
|
MutantStack<int>::const_iterator ite = mstack.end();
|
|
++it;
|
|
--it;
|
|
//*it = 20; // a constant iterator, should not work if uncommented
|
|
while (it != ite)
|
|
{
|
|
std::cout << *it << std::endl;
|
|
++it;
|
|
}
|
|
std::stack<int> s(mstack);
|
|
}
|
|
std::cout << std::endl;
|
|
|
|
|
|
return 0;
|
|
}
|