Advertisement
Guest User

gfhg

a guest
Oct 21st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include<stdio.h>
  2. #define size 10
  3. int s[size], top=-1;
  4. int sfull()
  5. {
  6. if(top==size-1) return 1;
  7.  
  8. return 0;
  9. }
  10. int sempty()
  11. {
  12. if(top==-1) return 1;
  13.  
  14. return 0;
  15. }
  16. void push(int item){
  17.  
  18. if(sfull()) printf("Overflow\n");
  19.  
  20. else{
  21.  
  22. ++top;
  23. s[top]=item;
  24. }
  25. }
  26. void pop()
  27. {
  28. if(sempty()) printf("Underflow\n");
  29.  
  30. else{
  31.  
  32. top--;
  33. }
  34. }
  35. void display()
  36. {
  37. for(int i=top; i>=0; i--) printf("%d ",s[i]);
  38. }
  39. int main()
  40. {
  41. push(5);
  42. push(10);
  43. push(15);
  44. push(20);
  45. push(25);
  46. display();
  47. pop();
  48. pop();
  49. printf("\n");
  50. display();
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement