Advertisement
asiffff

Queue

Feb 17th, 2019
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <stdio.h>
  2. int a[100],f=0,r=0,n,x=0;
  3. void insert()
  4. {
  5. if(x==0)
  6. {
  7. printf("Enter size of Queue:\n");
  8. scanf("%d",&n);
  9. x=1;
  10. }
  11. if(r==n && f==0)
  12. {
  13. printf("\nQueue is Full.\n");
  14. }
  15. else
  16. {
  17. printf("Enter Data:\n");
  18. int b;
  19. scanf("%d",&b);
  20. a[r]=b;
  21. r++;
  22.  
  23.  
  24. }
  25.  
  26. }
  27. void del()
  28. {
  29. if(r==0 && f==0)
  30. {
  31. printf("\nQueue is Empty.\n");
  32. }
  33. else
  34. {
  35. int i;
  36. printf("\nDeleted item is %d\n",a[f]);
  37. for(i=0;i<r-1;i++)
  38. {
  39. a[i]=a[i+1];
  40. }
  41. r--;
  42. }
  43. }
  44. void dis()
  45. {
  46. if(r==0 && f==0)
  47. {
  48. printf("Queue is Empty.\n");
  49.  
  50. }
  51. else
  52. {
  53. int i;
  54. for(i=f;i<r;i++)
  55. {
  56. printf("%d-->",a[i]);
  57. }
  58. }
  59. }
  60. int main()
  61. {
  62. int i;
  63. while(1)
  64. {
  65. printf("\nEnter 1 for add,Enter 2 for Delete,3 for Display.\n");
  66. scanf("%d",&i);
  67. switch(i)
  68. {
  69. case 1:
  70. {
  71. insert();
  72. break;
  73. }
  74. case 2:
  75. {
  76. del();
  77. break;
  78. }
  79. case 3:
  80. {
  81. dis();
  82. break;
  83. }
  84. default:
  85. printf("\nEnter a option.\n");
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement