Advertisement
tonygms3

Stack

Sep 3rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. const int SIZE = 10;
  4. int stack_Data[10];
  5. int top = -1;
  6. int push(int number);
  7. int pop();
  8. int Top();
  9. int main()
  10. {int counter = 0;
  11.     while(counter<10){
  12.         push(counter);
  13.         counter++;
  14.     }
  15.     while(counter<10){
  16.         printf("%d\n",stack_Data[counter]);
  17.     }
  18.     return 0;
  19. }
  20.  
  21.  
  22. int pop(){
  23.     int temp;
  24.     temp = stack_Data[top];
  25.     top--;
  26.     return temp;
  27. }
  28. int push(int number){
  29.     if(top>SIZE){
  30.         printf("Stack is full\n try popping a few elements\n");
  31.         return 1;
  32.     }
  33.     else{
  34.         top++;
  35.         stack_Data[top]=number;
  36.            }
  37.     return number;
  38. }
  39. int Top(){
  40.     if(top<0)
  41.         printf("Stack is now empty\n");
  42.         return -1;
  43. return stack_Data[top];
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement