#ifndef __STACK_HPP__ #define __STACK_HPP__ const int stack_size = 10; class Stack { protected: int top; int data[stack_size]; public: Stack() { top = -1; } bool isEmpty() { return (top == -1); } bool isFull() { return (top == stack_size - 1); } void push(int elem); int pop(); }; void Stack::push(int elem) { if (isFull()) { throw StackOverflowError("push", __FILE__, __LINE__); } data[top + 1] = elem; top++; } int Stack::pop() { if (isEmpty()) { throw StackUnderflowError(__FUNCTION__, __FILE__, __LINE__); } int rlt = data[top]; top--; return rlt; } #endif