1
0
Fork 0
This repository has been archived on 2021-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
uni-m.cds-adv-prog/ex7.4/Stack.hh
Eric Teunis de Boone d9cbe495da Finished ex7.*
2020-01-06 15:20:05 +01:00

47 lines
674 B
C++

//Stack.h
#include <deque>
#ifndef STACK_H
#define STACK_H
template<class T>
class Stack {
// Interface
public:
Stack() {
_s = new std::deque<T>();
}
int nitems() { return _s->size() ; }
bool empty() { return (_s->size() == 0) ; }
void push(T c) {
_s->push_back(c);
}
T pop() {
if (empty()) {
std::cout << "Stack::pop() Error: stack is empty" << std::endl ;
return 0 ;
}
T tmp = _s->back();
_s->pop_back();
return tmp;
}
void inspect() {
for ( auto iter = _s->begin(); iter != _s->end() ; iter++ )
{
std::cout << *iter << std::endl;
}
}
// Implementation
private:
std::deque<T>* _s ;
};
#endif