Advertisement
asiffff

Untitled

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