#include #include #include class stack { private: int *stack_ptr; int max_len, top_ptr; public: stack( int size) { stack_ptr = new int [size]; //constructor max_len = size - 1; top_ptr = -1; } ~stack() {delete [] stack_ptr;}; //destructor void push (int number) { if (top_ptr == max_len) cout << "error stack is full\n"; else stack_ptr[++top_ptr] = number; } int pop() { if (top_ptr == -1) { cout << "error stack is empty\n"; return 0;} else return (stack_ptr[top_ptr--]); } int top() {return (stack_ptr[top_ptr]);} int empty() {return (top_ptr == -1);} }; void main() { int t1, t2, t3; stack stk(100); //instance creation stk.push(25); stk.push(120); t1 = stk.top(); t2 = stk.pop(); t3 = stk.pop(); cout << t1 << " " << t2 << " " << t3 << endl; getch(); }