#include #include #include "stack_int.h" using namespace std; stack_int::~stack_int() { if (n != 0) { cerr << "Warning: stack still contains " << n << " value(s).\n"; } } //Push a value onto the stack. void stack_int::push(value_type i) { if (n == max_size) { //overflow cerr << "Can't push when size " << n << " == capacity " << max_size << ".\n"; exit(EXIT_FAILURE); } a[n++] = i; } //Pop a value off the stack. stack_int::value_type stack_int::pop() { if (n == 0) { //underflow cerr << "Can't pop when size " << n << " == 0.\n"; exit(EXIT_FAILURE); } return a[--n]; } bool operator==(const stack_int& s1, const stack_int& s2) { if (s1.n != s2.n) { return false; } for (size_t i = 0; i < s1.n; ++i) { if (s1.a[i] != s2.a[i]) { return false; } } return true; }