#include #include "stack.h" using namespace std; int Stac::MAXVAL = 100; Stac::Stac(){ _sp = 0; _val = new double[MAXVAL]; } Stac::Stac(int max){ _sp = 0; _val = new double[MAXVAL]; MAXVAL = max; } // copy constructor Stac::Stac(const Stac& st){ _sp = st._sp; _val = new double[MAXVAL]; for(int i = 0; i < st._sp; i++) _val[i] = st._val[i]; } Stac::~Stac(){ delete[] _val; } // push: push f onto value stack void Stac::push(double f){ if(_sp < MAXVAL) _val[_sp++] = f; else cerr << "error: stack full, can't push\n"; } // pop: pop and return top value from stack double Stac::pop(void){ if(_sp > 0) return _val[--_sp]; else{ cerr << "error: stack empty\n"; return 0.0; } } void Stac::maxval(int max){ MAXVAL = max; cout << "value of MAXVAL: " << MAXVAL << endl; } void Stac::maxval(void){ cout << "value of MAXVAL: " << MAXVAL << endl; }