Advertisement
Rakibul_Ahasan

Stack_Array_Simple

Aug 22nd, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. #define Max_Size 100
  5. int A[Max_Size];
  6. int top=0;
  7.  
  8. void push(int item)
  9. {
  10.     if(top<Max_Size){
  11.         A[top]=item;
  12.         top++;
  13.     }
  14.     else cout<<"Stack is Empty"<<endl;
  15. }
  16.  
  17. int pop()
  18. {
  19.     if(top==0) cout<<"Stack is Full!!"<<endl;
  20.     else
  21.     {
  22.         return A[--top];
  23.  
  24.     }
  25. }
  26.  
  27. int main()
  28. {
  29.    push(1);
  30.    push(2);
  31.    push(3);
  32.    for (int i=0; i<top; i++) cout<<A[i]<<" ";
  33.    cout<<endl;
  34.  
  35.    for (int i=0; i<2; i++)
  36.    cout<<pop()<<" ";
  37.    cout<<endl;
  38.  
  39.    for (int i=0; i<top; i++) cout<<A[i]<<" ";
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement