// File: StackAr.h // Array Stack Class Definition #ifndef STACK_AR_H #define STACK_AR_H template class Stack { public: // Constructor Stack(); // Observers int Empty(); int Full(); // Place an Item on Top void Push(StackElementType Data); // Remove the Top Element from the Stack void Pop(StackElementType &Data); // Return the Top Element without Removing it StackElementType TopElt(); // Return the Number of Elements in the Stack int NumElts(); private: int Top; StackElementType Info[MaxElts]; }; // File: StackAr.cpp // Array Stack ADT Implementation template Stack::Stack() {Top=0;} template int Stack::Empty() {return(!Top);} template int Stack::Full() {return(Top==MaxElts);} template void Stack::Push(StackElementType Data) {Info[Top++]=Data;} template void Stack::Pop(StackElementType &Data) {Data=Info[--Top];} template StackElementType Stack::TopElt() {return(Info[Top-1]);} template int Stack::NumElts() {return(Top);} #endif