Wednesday, October 1, 2014

WAP to implement the push and pop operation of stack using the concept of class and object. Use the default constructor of initialization of stack top as -1

#include
#include
#define max 10

class gostack
{
int counter,item,a[max];

public:
            gostack()
                        {
                        counter=-1;
                        }
            void push()
                        {
                        if(counter>=max)
                                    cout<
                        else
                        {
                                    counter++;
                                    cout<
                                    cin>>item;
                                    a[counter]=item;
                        }
            }

                        void pop()
                        {
                        if(counter<=-1)
                                    cout<
                        else
                        {
                                    cout<
                                    counter--;
                        }
            }
};
  void main()
{
clrscr();
gostack s1;
int a;
abc:
cout<
cin>>a;

switch(a)
{
case 1:
{
s1.push();
break;
}

case 2:
{
s1.pop();
break;
}

case 3:
{
goto last;
}
}

goto abc;
last:
getch();
}


No comments:

Post a Comment