#ifndef FILE_STACK #define FILE_STACK /*****************************************************************************/ /* File: stack.hh */ /* Author: Wolfram Muehlhuber */ /* Date: September 98 */ /*****************************************************************************/ /* Stack class, based on a resizable array */ #include "array.hpp" /// template class STACK { public: /// inline STACK (INDEX asize = 0, INDEX ainc = 0); /// inline ~STACK (); /// inline void Push (const T & el); /// inline T & Pop (); /// const inline T & Top () const; /// inline int IsEmpty () const; /// inline void MakeEmpty (); private: /// ARRAY elems; /// INDEX size; }; /* Stack class, based on a resizable array */ template inline STACK :: STACK (INDEX asize, INDEX ainc) : elems(asize, ainc) { size = 0; } template inline STACK :: ~STACK () { ; } template inline void STACK :: Push (const T & el) { if (size < elems.Size()) elems.Elem(++size) = el; else { elems.Append(el); size++; } } template inline T & STACK :: Pop () { return elems.Elem(size--); } template const inline T & STACK :: Top () const { return elems.Get(size); } template inline int STACK :: IsEmpty () const { return (size == 0); } template inline void STACK :: MakeEmpty () { size = 0; } #endif