#include using namespace std ; template class Stack { private: int size ; // number of elements on Stack. int top ; T* stackPtr ; public: Stack( int initSize = 10 ) { stackPtr = new T[ initSize ] ; top = -1 ; } ~Stack() { delete[] stackPtr ; } int push(const T& value) { if ( isFull() ) { cout << "Stack is full." << endl ; exit(1) ; } stackPtr[ ++top ] = value ; } T pop() { if ( isEmpty() ) { cout << "Stack is Empty." << endl ; exit(1) ; } T result ; result = stackPtr[ top ] ; top-- ; return result ; } int isEmpty()const { return top == -1 ; } int isFull() const { return top == size - 1 ; } } ; int main() { Stack s1 ; s1.push( 4 ) ; cout << s1.pop() << endl ; Stack s2 ; s2.push( "Alan" ) ; cout << s2.pop() << endl ; }