Code /* stackt.h CIS 250 Dave Klick Definition and implementation of a templated stack class which uses an array for storage. This class should really overload the assignment operator and copy constructor, but doesn't at the moment. */ #ifndef __STACKT_H_ #define __STACKT_H_ #include template class stackt { private: T* stk; int numItems; int size; void init(const int size); public: stackt(); stackt(const int size); ~stackt(); bool isEmpty() const; bool isFull() const; bool push(const T data); bool pop(T& data); }; template stackt::stackt() { init(10); } template stackt::stackt(int size) { init(size); } template void stackt::init(const int len) { size = len>0 ? len : 10; stk = new T[size]; numItems = 0; } template stackt::~stackt() { if (stk) delete[] stk; stk = NULL; numItems = 0; size = 0; } template bool stackt::isEmpty() const { return numItems==0; } template bool stackt::isFull() const { return numItems==size; } template bool stackt::push(const T data) { if (isFull()) return false; stk[numItems++] = data; return true; } template bool stackt::pop(T& data) { if (isEmpty()) return false; data = stk[--numItems]; return true; } #endif