#include<iostream>
#include<typeinfo>
#include<iomanip>

#define MAX 20

using namespace std;

template <typename DataType>
class Stack
{
    private:
        DataType Element[MAX];
        int Count;
    public:
        Stack():Count(0){}
        Stack(DataType a)
        {
            Element[0]=a;
            Count=1;
        }
        void Push(DataType a)
        {
            if(Count>MAX)
                cout<<"\t\t Fatal Error !! Stack Full "<<endl;
            else
            {
                Element[Count]=a;
                Count++;
            }
        }
        DataType Pop()
        {
            if(Count<1)
                cout<<"\t\t Fatal Error!! Stack Empty"<<endl;
            else
            {
                Count--;
                return Element[Count];
            }
        }
        void ShowSize()
        {
            cout<<" The stack size is "<<Count<<endl;
        }
};


int main()
{
    Stack <char> a(45);
    a.ShowSize();
    a.Push(34);
    a.Push(43);
    a.ShowSize();
    cout<<" Here : "<<a.Pop()<<endl;
    a.ShowSize();
    cout<<" Here : "<<a.Pop()<<endl;
    a.ShowSize();
    cout<<" Here : "<<a.Pop()<<endl;
    a.ShowSize();
    cout<<" Here : "<<a.Pop()<<endl;
    a.ShowSize();

}
Advertisements