Advertisement
Saboten758

:D

Nov 7th, 2022
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define MAX 100
  4. typedef struct member{
  5. int data[MAX];
  6. int front;
  7. int back;
  8. }member;
  9. member insertion(int,member);
  10. member deletion(member);
  11. int overflow(member);
  12. int underflow(member);
  13. void display(member);
  14. int main()
  15. {
  16. system("clear||cls");
  17. member q;
  18. q.front=-1;
  19. q.back=-1;
  20. int num;
  21. printf("Enter a number:");
  22. scanf("%d",&num);
  23. int temp=num,digit;
  24. while(temp!=0)
  25. {
  26. digit=temp%10;
  27. q=insertion(digit,q);
  28. if(digit%2!=0)
  29. {
  30. q=deletion(q);
  31. }
  32. temp=temp/10;
  33. }
  34. printf("The Queue looks like:");
  35. display(q);
  36. return 0;
  37. }
  38. member insertion(int val,member a)
  39. {
  40. if(a.front==-1) a.front+=1;
  41. a.back+=1;
  42. if(overflow(a)!=1)
  43. {
  44. a.data[a.back]=val;
  45. }
  46. return a;
  47. }
  48. int overflow(member a)
  49. {
  50. if(a.front>a.back || a.back>MAX)
  51. {
  52. return 1;}
  53. return 0;
  54. }
  55. int underflow(member a)
  56. {
  57. if(a.front>a.back || a.front==-1 || a.back==-1) return 1;
  58. return 0;
  59. }
  60. void display(member a)
  61. {
  62. for(int i=a.front;i<=a.back;i++)
  63. {
  64. printf("%d->",a.data[i]);
  65. }
  66. printf("END\n");
  67. }
  68. member deletion(member a)
  69. {
  70. if(underflow(a)!=1)
  71. {
  72. printf("%d has been dequeued!\n",a.data[a.front++]);
  73. for(int i=a.front;i<=a.back;i++)
  74. {
  75. a.data[i-1]=a.data[i];
  76. }
  77. a.front-=1;
  78. a.back-=1;
  79. return a;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement