Guest User

Untitled

a guest
Nov 14th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define MAX 10
  4. struct queue
  5. {
  6. int rear;
  7. int front;
  8. int q[MAX];
  9. };
  10. void insert(struct queue *s,int item);
  11. void del(struct queue *s);
  12. void display(struct queue *s);
  13. int main()
  14. { int ch,item;
  15. struct queue q;
  16. q.rear=0;
  17. q.front=0;
  18. while(1)
  19. {
  20. printf("Enter your choice\n1.Insert\n2.Delete\n3.Display\n4.Exit");
  21. scanf("%d",&ch);
  22. switch(ch)
  23. {
  24. case 1:printf("Enter the element to be inserted");
  25. scanf("%d",&item);
  26. insert(&q,item);
  27. break;
  28. case 2:del(&q);
  29. break;
  30. case 3:display(&q);
  31. break;
  32. case 4: exit(0);
  33.  
  34. }
  35. }
  36. return 0;
  37. }
  38. void insert(struct queue *s,int item)
  39. {
  40. if(s->rear==MAX-1)
  41. {
  42. printf("Queue is full");
  43. return;
  44. }
  45. s->q[s->rear]=item;
  46. s->rear++;
  47. return;
  48. }
  49. void del(struct queue *s)
  50. {
  51. if(s->front==s->rear)
  52. {
  53. printf("Queue is empty");
  54. return;
  55. }
  56. printf("Deleted element is %d",s->q[s->front]);
  57. s->front++;
  58. }
  59. void display(struct queue *s)
  60. {
  61. for(int i=s->front;i<s->rear;i++)
  62. printf("%d",s->q[i]);
  63. return;
  64.  
  65. }
Add Comment
Please, Sign In to add comment