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

43 lines
620 B
C++

//Stack.h
#include <deque>
#ifndef STACK_H
#define STACK_H
template<class T>
class Stack {
// Interface
public:
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