Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. #define MAX 5
  4.  
  5. class stack
  6. {
  7.     private:
  8.         int arr[MAX];
  9.         int top;
  10.     public:
  11.         stack()
  12.         {
  13.             top=-1;
  14.         }
  15.        
  16.         void push(int num)
  17.         {
  18.             top++;
  19.             if(top<MAX)
  20.             {
  21.                 arr[top]=num;
  22.                
  23.             }
  24.             else
  25.             {
  26.                 cout << "full";
  27.                 top--;
  28.             }
  29.         }
  30.        
  31.         int pop()
  32.         {
  33.             if(top==-1)
  34.             {
  35.                 cout << "empty";
  36.                 return NULL;
  37.             }
  38.             else
  39.             {
  40.                 int x=arr[top];
  41.                 arr[top]=NULL;
  42.                 top--;
  43.                 return x;
  44.             }
  45.         }
  46.     };
  47.    
  48.    
  49.     int main()
  50.     {
  51.         stack a;
  52.         int y;
  53.         for(int ctr=0;ctr<5;ctr++)
  54.         {
  55.             cin >> y;
  56.             a.push(y);
  57.         }
  58.         for(int ctr=0;ctr<5;ctr++)
  59.         {
  60.             cout << a.pop() << " ";
  61.         }
  62.        
  63.        
  64.         system("pause");
  65.         return 0;
  66.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement