/* FXSTK is an implementation of the stack data type, fully templated and defaulted. FXSTK gets BOTH the class type and size of stack at instantiation. The size defaults to 25, but may be any size wished, by merely altering the instantiation of the object. Written: 04 Dec 01 By Warren M Myers Updated: 04 Dec 01 WMM - original edition 15 Dec 01 WMM - improved clear()'s efficiency - changed SIZE to fxSIZE to steer clear other 'SIZE' declarations 16 Dec 01 WMM - added dumpstk, requiring to have '<<' operator defined 29 Dec 01 WMM - fixed push to handle const vals */ #ifndef _FXSTK_H_ #define _FXSTK_H_ template class fxstk{ private: T stack[fxSIZE]; int top; public: fxstk(){ top=-1;} bool settos(T x){ if(0>top) return false; stack[top] = x; return true; } bool lose(){ if(0>top) return false; top--; return true; } bool tos(T &x){ if(0>top) return false; x = stack[top]; return true; } bool push(T x){ top++; if(fxSIZE<=top){ top=fxSIZE-1; return false;} stack[top] = x; return true; } bool pop(T &x){ if(0>top) return false; x = stack[top--]; return true; } void clear(){ top=-1;} void dumpstk(ostream &out){ out << "stack dump\n"; for(int k=0;k<=top;k++) out << "\tpos" << top-k << stack[k] << endl; out << "empty space: " << (fxSIZE-top)-1 << endl; } }; #endif