#ifndef __T_STACK__ #define __T_STACK__ #include #include const int STACK_SIZE = 1000; template class Stack { private: T s[STACK_SIZE]; int tos; public: Stack(); bool isEmpty(); bool isFull(); void push(T elem); T pop(); // to pop out the top element T top(); // to peek the top element without popping it out }; template Stack::Stack() { tos = -1; // empty stack } template bool Stack::isEmpty() { return (tos == -1); } template bool Stack::isFull() { return (tos == STACK_SIZE -1); } template void Stack::push(T elem) { //if (isFull()) // return; assert(!isFull()); tos++; s[tos] = elem; } template T Stack::pop() { assert(!isEmpty()); T rlt = s[tos]; tos--; return rlt; } template T Stack::top() { assert(!isEmpty()); T rlt = s[tos]; return rlt; } #endif