#include using namespace std; template class Stack { public: Stack (int m); ~Stack (); int StackIsFull(); int StackIsEmpty(); void Push(x e); void Pop(x& e); void PrintStack(); private: int maxsize; int top; x *p; }; int main(){ Stack s1(10); s1.Push(2); s1.Push(4); s1.Push(6); s1.PrintStack(); return 0; } template Stack::Stack(int m){ maxsize = m; top = -1; p = new x[maxsize]; } template Stack::~Stack(){ delete [] p; } template int Stack::StackIsFull(){ if (top == maxsize - 1) return 1; return 0; } template int Stack::StackIsEmpty(){ if (top == -1) return 1; return 0; } template void Stack::Push(x e){ if (!StackIsFull()){ top++; p[top] = e; } } template void Stack::Pop(x &e){ if (!StackIsEmpty()){ e = p[top]; top--; } } template void Stack::PrintStack(){ x e; if (!StackIsEmpty()){ Pop(e); PrintStack(); cout << e << endl; Push(e); } }