Advertisement
HmHimu

Queue error in main

Feb 27th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4.  
  5. struct Node{
  6. int data;
  7. struct Node *next;
  8. }*node,*temp;
  9.  
  10. struct Head{
  11. int count;
  12. struct Node *front,*rear;
  13. }*head;
  14.  
  15. void create_queue()
  16. {
  17. head=(struct Head*)malloc(sizeof(struct Head));
  18. head->count=0;
  19. head->front=NULL;
  20. head->rear=NULL;
  21. }
  22. void first_node()
  23. {
  24. node=(struct Node*)malloc(sizeof(struct Node));
  25. printf("Plz input data in QueUe\n");
  26. scanf("%d",&node->data);
  27. node->next=NULL;
  28. head->front=node;
  29. head->rear=node;
  30. head->count++;
  31. }
  32.  
  33. void Enqueue()
  34. {
  35. node=(struct Node*)malloc(sizeof(struct Node));
  36. printf("Plz input data in QueUe\n");
  37. scanf("%d",&node->data);
  38. node->next=NULL;
  39. head->rear->next=node;
  40. head->rear=node;
  41. head->count++;
  42.  
  43. }
  44.  
  45. void Dequeue()
  46. {
  47. temp=head->front;
  48. head->front=temp->next;
  49. printf("%d is delated from Queue\n",temp->data);
  50. free(temp);
  51. head->count--;
  52.  
  53. }
  54.  
  55. void show()
  56. {
  57. int i;
  58. temp=head->front;
  59. for( i=0;i<head->count;i++)
  60. {
  61. printf("%d",temp->data);
  62. temp=temp->next;
  63. }
  64. }
  65.  
  66. int main()
  67. {
  68. int i;
  69.  
  70. while(1)
  71. {
  72. printf("Select ur Choice");
  73. printf("Press 1 to create queue");
  74. printf("Press 2 For Enqueue");
  75. printf("Press 3 For Dequeue");
  76.  
  77. switch(i){
  78.  
  79. case 1:
  80. {
  81. if(head->count==0){
  82. create_queue();
  83. }
  84. else
  85. printf("Al ready Queue is Created/Exist\n");
  86. break;
  87. }
  88. case 2:
  89. {
  90. if(head->count>=1){
  91. Enqueue();
  92. }
  93. else
  94. printf("First Create a queue\n");
  95. break;
  96. }
  97.  
  98. case 3:
  99. {
  100.  
  101. if(head->count>=1){
  102. Dequeue();
  103. }
  104. else
  105. printf("First Insert data in Queue\n");
  106. break;
  107. }
  108. default:
  109. printf("Wrong Choice.PLz select Right option\n");
  110. break;
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement