apl-mhd

stackArray

Apr 21st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int index =-1;
  5. int number[100];
  6. int size=1;
  7. void push(int x){
  8.    
  9.     if(index+1==size){
  10.         cout<<"overFlow\n";
  11.         }
  12.     else{
  13.     index++;
  14.     number[index] = x;
  15. }
  16.     }
  17.    
  18. int top(){
  19.    
  20.    
  21. return number[index];  
  22.     }
  23.    
  24. void pop(){
  25.    
  26.     if(index<0)
  27.         cout<<"underflow";
  28.     else
  29.     index-=1;
  30.    
  31.     }
  32.    
  33.    
  34.    
  35. void display(){
  36.    
  37.     for(int i=0;i<=index;i++)
  38.         cout<<number[i]<<" ";
  39.         cout<<endl;
  40.    
  41.     }
  42.  
  43. int main(int argc, char **argv)
  44. {
  45.     push(10);
  46.     pop();
  47.     push(10);
  48.     display();
  49.    
  50.    
  51.    
  52.    
  53.     return 0;
  54. }
Add Comment
Please, Sign In to add comment