asiffff

Queue

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