Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define max 10
  4.  
  5.  
  6. struct stack
  7. {
  8.  
  9. int top;
  10. int items[max];
  11.  
  12.  
  13. }s;
  14. void push();
  15. void pop();
  16. void display();
  17.  
  18. void main()
  19. {
  20. s.top=-1;
  21. int choice;
  22. top1:
  23.  
  24. printf("1.push\n2.pop\n3.display\n4.exit");
  25. scanf("%d",&choice);
  26. switch(choice){
  27. case 1:
  28. push();
  29. break;
  30. case 2:
  31. pop();
  32. break;
  33. case 3:
  34. display();
  35. break;
  36. case 4:
  37. exit(0);
  38. default:
  39. printf("Enter number in range: ");
  40. }
  41. goto top1;
  42. }
  43.  
  44.  
  45. void push(){
  46. if((s.top)==max-1)
  47. {
  48. printf("Stack overflow");
  49. }
  50. else{
  51. int d;
  52. s.top=s.top+1;
  53. printf("Enter the element: ");
  54. scanf("%d",&s.items[s.top]);
  55.  
  56.  
  57. }
  58. }
  59.  
  60. void pop(){
  61. if(s.top==-1)
  62. {
  63. printf("Stack underflow");
  64. }
  65. s.top=s.top-1;
  66.  
  67. }
  68.  
  69.  
  70. void display(){
  71. printf("The element are");
  72. printf("\n [");
  73. int i;
  74. for(i=0;i<=s.top;i++)
  75. {
  76.  
  77. printf(" %d ",s.items[i]);
  78. }
  79. printf("]");
  80.  
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement