Advertisement
apl-mhd

Bappy sir Stack Implemention

Mar 28th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4. #define MAXSIZE 5
  5. int number[MAXSIZE];
  6. int top=-1;
  7.  
  8. void Push(int x){
  9.        
  10.     if(top == MAXSIZE -1){
  11.         cout<<"Error: Overflow !"<<endl;
  12.         return;
  13.     }
  14.    
  15.     number[++top] = x;
  16.    
  17. }
  18.  
  19. void Pop(){
  20.    
  21.     if(top == -1)
  22.     cout<<"Error:Underflow."<<endl;
  23.    
  24.     else
  25.         top--;
  26.    
  27. }
  28.  
  29. void Top(){
  30.        
  31.     printf("%d\n", number[top]);
  32.    
  33. }
  34.  
  35.  
  36. void Print(){
  37.    
  38.     for(int i=0; i<=top; i++){
  39.        
  40.         cout<<number[i]<<" ";
  41.         }
  42.     cout<<endl;
  43.    
  44.     }
  45.  
  46.  
  47. int main(int argc, char **argv)
  48. {
  49.     Push(1);
  50.     Push(2);
  51.     Push(3);
  52.     Push(4);
  53.     Push(5);
  54.    
  55.    
  56.     Print();
  57.    
  58.     Pop();
  59.     Pop();
  60.     Pop();
  61.     Pop();
  62.    
  63.    
  64.     Top();
  65.    
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement