fork download
  1. #include<stdio.h>
  2.  
  3.  
  4. int st[1000],ch,num,top,a,i,op;
  5. void push();
  6. void pop();
  7. void topel();
  8. void display();
  9. void main()
  10. {
  11. top=-1;
  12. scanf("%d",&num); //max siz of stack
  13. scanf("%d",&op);
  14.  
  15. while(op--)
  16. {
  17. scanf("%d",&ch);
  18. switch(ch)
  19. {
  20. case 0:
  21. {
  22. exit(0);
  23.  
  24. }
  25. case 1:
  26. {
  27. push();
  28. display();
  29. break;
  30. }
  31. case 2:
  32. {
  33. pop();
  34. display();
  35. break;
  36. }
  37. case 3:
  38. {
  39. topel();
  40. break;
  41. }
  42. case 4:
  43. {
  44. display();
  45. break;
  46. }
  47. case 5:
  48. {
  49. printf("\n\t EXIT POINT ");
  50. break;
  51. }
  52. default:
  53. {
  54. printf ("\n Wrong Choice");
  55. break;
  56. }
  57. return;
  58. }
  59. }
  60. }
  61. void push()
  62. {
  63. if(top>=num-1)
  64. {
  65. printf("\n\tSTACK is over flow");
  66. return;
  67. }
  68. else
  69. {
  70. scanf("%d",&a); //value to b pushed
  71. top++;
  72. st[top]=a;
  73. }
  74. }
  75. void pop()
  76. {
  77. int y;
  78. if(top<=-1)
  79. {
  80. printf("\n\t Stack is under flow");
  81. }
  82. else
  83. {
  84. y=st[top];
  85. top--;
  86. }
  87. }
  88.  
  89. void topel()
  90. {
  91. if(top>=0)
  92. {
  93. printf("%d\n",st[top]);
  94. }
  95. else
  96. {
  97. printf("\n The STACK is empty");
  98. }
  99. }
  100. void display()
  101. {
  102. if(top>=0)
  103. {
  104. for(i=top; i>=0; i--)
  105. printf("%d ",st[i]);
  106. }
  107. else
  108. {
  109. printf("\n The STACK is empty");
  110. }
  111. printf("\n");
  112. }
  113.  
Success #stdin #stdout 0s 9432KB
stdin
100
10
1 3
1 4
3
4
1 10
2
1 12
2
2
0
stdout
3 
4 3 
4
4 3 
10 4 3 
4 3 
12 4 3 
4 3 
3