#include #include #include template //Type is parameter class stack3 { private: Type *stack_ptr; int max_len, top_ptr; public: stack3(Type size) { //constructor stack_ptr = new Type [size]; max_len = size - 1; top_ptr = -1; } ~stack3() {delete [] stack_ptr;}; //destructor void push (Type number) { if (top_ptr == max_len) cout << "error stack is full\n"; else stack_ptr[++top_ptr] = number; } void pop() { if (top_ptr == -1) cout << "error stack is empty\n"; else top_ptr--; } Type top() {return (stack_ptr[top_ptr]);} int empty() {return (top_ptr == -1);} }; void main() { int t1, t2; stack3 stki(100); //instance int stack creation stki.push(25); stki.push(120); t1 = stki.top(); stki.pop(); t2 = stki.top(); cout << t1 << " " << t2 << " " << endl; char c1, c2; stack3 stkc(50); //instance char stack creation stkc.push('a'); stkc.push('b'); c1 = stkc.top(); stkc.pop(); c2 = stkc.top(); cout << c1 << " " << c2 << " " << endl; getchar(); }