Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include<stdio.h>
  2. #define size 6
  3. int s[size],top=-1;
  4.  
  5. int sFull()
  6. {
  7. if(top==size-1)
  8. return 1;
  9. return 0;
  10. }
  11.  
  12. int sEmpty()
  13. {
  14. if(top==-1)
  15. return 1;
  16. return 0;
  17. }
  18.  
  19. void push(value)
  20. {
  21. if(sFull())
  22. printf("overflow");
  23. else
  24. {
  25. top++;
  26. s[top]=value;
  27. }
  28. }
  29.  
  30. void pop()
  31. {
  32. if(sEmpty())
  33. printf("Underflow");
  34. else
  35. {
  36. top--;
  37. }
  38. }
  39. void display()
  40. {
  41. int i;
  42.  
  43. if(top==-1)
  44. {
  45. printf("\nStack is empty...");
  46. }
  47. else
  48. {
  49. for(i=top;i>=0;--i)
  50. printf("%d\n",s[i]);
  51. }
  52. }
  53.  
  54. int main()
  55. {
  56. push(16);
  57. push(7);
  58. push(5);
  59. pop();
  60. display();
  61.  
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement