C++ Programming Blog

 
 
 

Image

 #include<iostream.h>
 #include<conio.h>



 //------------------------------  stack  --------------------------------//


 class stack
    {
       private:
        int st[25];
        int top;

       public:
        stack() { top=-1; }
        void push(int);
        int pop();
    };




 //---------------------------  push(int)  -------------------------------//


 void stack::push(int variable)
    {
       top++;
       st[top]=variable;
    }


 //-------------------------------  pop( )  ------------------------------//


 int stack::pop()
    {
       return st[top--];
    }


 main()
    {
       clrscr();

       stack obj;

       obj.push(11);
       obj.push(22);

       cout<<\"1:\"<<obj.pop()<<endl;
       cout<<\"2:\"<<obj.pop()<<endl;

       obj.push(33);
       obj.push(44);
       obj.push(55);
       obj.push(66);

       cout<<\"3:\"<<obj.pop()<<endl;
       cout<<\"4:\"<<obj.pop()<<endl;
       cout<<\"5:\"<<obj.pop()<<endl;
       cout<<\"6:\"<<obj.pop()<<endl;

       getch();
       return 0;
    }

 
 
Didn't find what you were looking for? Find more on Program to illustrate use of arrays as data items in classes