fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node
  4. {
  5. int a;
  6. struct node* next;
  7. };
  8.  
  9. node* head;
  10. node* tail;
  11.  
  12. void printlist()
  13. {
  14. node* temp;
  15. temp=head;
  16. printf("Now the Queue is-> ");
  17. while(temp!=NULL)
  18. {
  19. printf("%d ",temp->a);
  20. temp=temp->next;
  21. }
  22. puts("");
  23. }
  24.  
  25. void add(int x)
  26. {
  27.  
  28. if(head==NULL)
  29. {
  30. head=(node*) malloc(sizeof(node));
  31. head->a=x;
  32. head->next=NULL;
  33.  
  34. tail=head;
  35. }
  36. else
  37. {
  38. node* temp=(node*) malloc(sizeof(node));
  39.  
  40. temp->a=x;
  41. temp->next=NULL;
  42. tail->next=temp;
  43. tail=temp;
  44. }
  45.  
  46. }
  47. void del()
  48. {
  49. if(head==NULL)
  50. {
  51. printf("Queue is empty\n");
  52. }
  53. else
  54. {
  55. printf("Deleted item is: %d\n",head->a);
  56. node* temp=(node*) malloc(sizeof(node));
  57.  
  58. temp=head;
  59. head=head->next;
  60. temp->next=NULL;
  61. free(temp);
  62.  
  63. printlist();
  64. }
  65. }
  66.  
  67. int main()
  68. {
  69. int i,num;
  70.  
  71.  
  72. while(~scanf("%d",&num) && num)
  73. {
  74. switch(num)
  75. {
  76. case 1:
  77. scanf("%d",&i);
  78.  
  79. add(i);
  80. printlist();
  81. break;
  82. case 2:
  83. del();
  84. break;
  85. case 3:
  86. break;
  87. }
  88. }
  89. return 0;
  90. }
  91.  
Success #stdin #stdout 0s 2988KB
stdin
1
10
1
20
1
30
2
2
2
2
3
stdout
Now the Queue is-> 10 
Now the Queue is-> 10 20 
Now the Queue is-> 10 20 30 
Deleted item is: 10
Now the Queue is-> 20 30 
Deleted item is: 20
Now the Queue is-> 30 
Deleted item is: 30
Now the Queue is-> 
Queue is empty