Advertisement
S_h_u_v_r_o

Queue

Mar 24th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include<stdio.h>
  2. #define SIZE 5
  3.  
  4. void enQueue(int);
  5. void deQueue();
  6. void display();
  7.  
  8. int items[SIZE], front = -1, rear = -1;
  9.  
  10. int main()
  11. {
  12. int a,b,c,d;
  13. scanf("%d",&a);
  14. for(b=0; b<a; b++)
  15. {
  16. scanf("%d",&c);
  17. enQueue(c);
  18. }
  19. display();
  20. scanf("%d",&a);
  21. for(b=0; b<a; b++)
  22. {
  23. deQueue(c);
  24. }
  25. display();
  26.  
  27. return 0;
  28.  
  29. }
  30.  
  31. void enQueue(int value)
  32. {
  33. if(rear == SIZE-1)
  34. printf("\nQueue is Full!!");
  35. else
  36. {
  37. if(front == -1)
  38. front = 0;
  39. rear++;
  40. items[rear] = value;
  41. printf("\nInserted -> %d", value);
  42. }
  43. }
  44.  
  45. void deQueue()
  46. {
  47. if(front == -1)
  48. printf("\nQueue is Empty!!");
  49. else
  50. {
  51. printf("\nDeleted : %d", items[front]);
  52. front++;
  53. if(front > rear)
  54. front = rear = -1;
  55. }
  56. }
  57.  
  58. void display()
  59. {
  60. if(rear == -1)
  61. printf("\nQueue is Empty!!!");
  62. else
  63. {
  64. int i;
  65. printf("\nQueue elements are:\n");
  66. for(i=front; i<=rear; i++)
  67. printf("%d\t",items[i]);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement