//Stack.h #include "Array.hh" #ifndef STACK_H #define STACK_H template class Stack { // Interface public: Stack( int size ): _s(size, 0) {} int nitems() { return count ; } bool full() { return (count == _s.size()) ; } bool empty() { return (count == 0) ; } void push(T c) { if (full()) { std::cout << "Stack::push() Error: stack is full" << std::endl ; _s.resize( _s.size() + 10 ); } _s[count++] = c ; } T pop() { if (empty()) { std::cout << "Stack::pop() Error: stack is empty" << std::endl ; return 0 ; } return _s[--count] ; } void inspect() { for ( int i = nitems() - 1; i >= 0; i-- ) { std::cout << i << ": " << _s[i] << std::endl; } } // Implementation private: Array _s ; int count = 0; }; #endif