Advertisement
Guest User

Untitled

a guest
May 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. int head=0;
  5. int tail=0;
  6. int maxsize=6;
  7. int item;
  8. int queue[6];
  9. void enqueue()
  10. {
  11.  
  12. if(head==(tail+1)%maxsize)
  13. {
  14.  
  15. printf("queue is full");
  16.  
  17. }
  18. else
  19. {
  20.  
  21. scanf("%d",&item);
  22. queue[tail]=item;
  23. ///new thing is added
  24. tail=(tail+1)%maxsize;
  25. printf("the item that went into the queue=%d\n\n",item);
  26.  
  27. }
  28.  
  29. }
  30.  
  31. void dequeue()
  32. {
  33.  
  34. if(head==tail)
  35. {
  36.  
  37. printf("queu is empty");
  38.  
  39. }
  40. else
  41. {
  42.  
  43. item=queue[head];
  44. ///add a new thing
  45. head=(head+1)%maxsize;
  46. printf("item that gets out of the queue=%d",item);
  47.  
  48. }
  49. }
  50. void traverse()
  51. {
  52.  
  53. int i;
  54. printf("the items of the queue are \n\n");
  55. for(i=head;i<=tail;i++)
  56. {
  57.  
  58.  
  59.  
  60.  
  61. item=queue[i];
  62. printf("%d\n\n",item);
  63.  
  64. }
  65. }
  66. int main()
  67. {
  68.  
  69. int i,n;
  70. do
  71. {
  72.  
  73. printf("1-enqueue\n2-dequeue\n3-traverse\n4-exit\n\n");
  74. scanf("%d",&n);
  75.  
  76. switch(n)
  77. {
  78.  
  79. case 1:
  80. enqueue();
  81. break;
  82. case 2:
  83. dequeue();
  84. break;
  85. case 3:
  86. traverse();
  87. break;
  88. case 4:
  89. break;
  90.  
  91. }}while(n!=4);
  92. return 0;
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement