hasan-mahmudz

sdfgh

Mar 17th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define max 5
  4. int top,stack[max],i;
  5.  
  6.  
  7. void push ()
  8. {
  9. int value ;
  10. if(top==max-1) printf("overload \n");
  11. else
  12. {
  13. printf("Enter element to push");
  14. scanf("%d",&value);
  15. top=top+1;
  16. stack[top]=value;
  17. }
  18. }
  19.  
  20. void pop()
  21. {
  22. if(top==-1) printf("No element \n");
  23. else
  24. {
  25. printf("deleted element %d \n",stack[top]);
  26. top=top-1;
  27. }
  28. }
  29.  
  30. void desplay()
  31. {
  32. if(top==-1) printf("No element");
  33. else
  34. {
  35. printf("\n stack is \n");
  36. for(i=top; i>0; --i)
  37. printf("%d ",stack[i]);
  38. }
  39. }
  40.  
  41. void main()
  42. {
  43. int op;
  44. while(1)
  45. {
  46. printf("\n stack menu \n");
  47. printf("1.push\n2.pop\n3.display\n4.exit\n");
  48. printf("Enter the chose: ");
  49. scanf("%d",&op);
  50.  
  51. if(op==1)
  52. {
  53. push();
  54. }
  55. else if(op==2)
  56. {
  57. pop();
  58. }
  59. else if(op==3)
  60. {
  61. desplay();
  62. }
  63. else
  64. {
  65. break;
  66. }
  67.  
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment