1
0
Fork 0

Ex7.4 feedback: change _s pointer to member attribute

This commit is contained in:
Eric Teunis de Boone 2020-07-09 16:57:17 +02:00
parent f0ec419a8a
commit 83318d7e73

View file

@ -8,18 +8,11 @@ template<class T>
class Stack {
// Interface
public:
Stack() {
_s = new std::deque<T>();
}
~Stack() {
delete _s;
}
int nitems() { return _s->size() ; }
bool empty() { return (_s->size() == 0) ; }
int nitems() { return _s.size() ; }
bool empty() { return (_s.size() == 0) ; }
void push(T c) {
_s->push_back(c);
_s.push_back(c);
}
T pop() {
@ -28,15 +21,15 @@ class Stack {
return 0 ;
}
T tmp = _s->back();
_s->pop_back();
T tmp = _s.back();
_s.pop_back();
return tmp;
}
void inspect() {
for ( auto iter = _s->begin(); iter != _s->end() ; iter++ )
for ( auto iter = _s.begin(); iter != _s.end() ; iter++ )
{
std::cout << *iter << std::endl;
}
@ -44,7 +37,7 @@ class Stack {
// Implementation
private:
std::deque<T>* _s ;
std::deque<T> _s ;
};
#endif