47 lines
674 B
C++
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
|