5.3 Formula-based representation We may use the Formula-based representation 012 top maxtop-l stack when Top==-1 is empty stack
5.3 Formula-based Representation We may use the Formula-based representation when Top=-1 is empty stack stack 0 1 2 top maxtop-1
5.3 Formula-based Representation Formula-based class stack template<class T> class Stack //LIFO objects publiC Stack(int MaxStackSize=10) Stackoi delete stack; 1 bool isemptyoconst return top==--1 bool IsFulloconst return top== Top; 1
5.3 Formula-based Representation • Formula-based class Stack template<class T> class Stack { //LIFO objects public: Stack(int MaxStackSize=10); ~Stack(){delete [] stack;} bool IsEmpty()const {return top==-1;} bool IsFull()const{return top==MaxTop;}
5.3 Formula-based Representation T TopOconst Stack <T>& add(const T& x) Stack<T>& delete& x) Private int top; /current top of a stack int MaxTop; //max value for top T* stack; /element array
5.3 Formula-based Representation T Top()const; Stack<T>& Add(const T& x); Stack<T>& Delete(T& x); Private: int top; //current top of a stack int MaxTop; //max value for top T* stack; //element array };