Static Stack

#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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s