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