Advertisement
asiffff

Queue Using Doubly

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