Advertisement
HmHimu

queue3

Feb 27th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. struct Node
  4. {
  5. int data;
  6. struct Node *next;
  7. } *temp,*temp2, *node;
  8.  
  9. struct Head
  10. {
  11. int count;
  12. struct Node *first;
  13. struct Node *last;
  14. } *head;
  15.  
  16. void Head_create()
  17. {
  18. head = (struct Head*) malloc(sizeof(struct Head));
  19. head->count = 0;
  20. head->first = NULL;
  21. head->last = NULL;
  22. }
  23.  
  24. void Enque(int value)
  25. {
  26. node=(struct Node*)malloc(sizeof(struct Node));
  27. node->data = value;
  28. node->next=NULL;
  29. if(head->count==0)
  30. {
  31. head->first=node;
  32. head->last=node;
  33. (head->count)++;
  34. }
  35. else
  36. {
  37. head->last->next=node;
  38. head->last=node;
  39. (head->count)++;
  40. }
  41. }
  42.  
  43. void Deque()
  44. {
  45. //temp=head->first;
  46. if(head->count == 0)
  47. printf("\t\tqueue is empty.\n");
  48. else if(head->count == 1)
  49. {
  50. temp=head->first;
  51. temp2=head->last;
  52. head->last=NULL;
  53. head->first=NULL;
  54. free(temp);
  55. free(temp2);
  56. (head->count)--;
  57. }
  58. else
  59. {
  60. temp=head->first;
  61. head->first=head->first->next;
  62. (head->count)--;
  63. free(temp);
  64. }
  65. }
  66. void Search_values(int value)
  67. {
  68. int flag = 0,i;
  69. for(temp = head->first,i=1; temp != NULL; temp = temp->next,i++)
  70. {
  71. if(temp->data == value)
  72. {
  73. printf("\t\t%d Found in the queue in %d th position.\n",temp->data,i);
  74. flag=1;
  75. break;
  76. }
  77. }
  78. if(flag == 0)
  79. {
  80. printf("\t\t%d not Found in the queue!\n",value);
  81. }
  82. }
  83.  
  84. void Show_values()
  85. {
  86. temp = head->first;
  87. if(head->count==0)
  88. printf("\t\tNo values in the queue!!\n");
  89. else{
  90. printf("\t\tCurrent Values in the queue\n");
  91. while(temp != NULL)
  92. {
  93. printf("\t\t-> %d",temp->data);
  94. temp = temp->next;
  95. }
  96. }
  97. }
  98.  
  99.  
  100. void Rear()
  101. {
  102. if(head->count!=0)
  103. {
  104. printf("\t\tRear is: %d",head->last->data);
  105. }
  106. else
  107. printf("\t\tqueue is empty.\n");
  108. }
  109. void Front()
  110. {
  111. if(head->count!=0)
  112. {
  113. printf("\t\tFront is: %d",head->first->data);
  114. }
  115. else
  116. printf("\t\tqueue is empty.\n");
  117. }
  118.  
  119. void Menu_function()
  120. {
  121.  
  122. }
  123.  
  124. int Take_number()
  125. {
  126. int value;
  127. printf("\t\tEnter a value: ");
  128. scanf("%d", &value);
  129. return value;
  130. }
  131.  
  132. int main()
  133. {
  134. int choice;
  135. Head_create();
  136. for( ; ; )
  137. {
  138. Menu_function();
  139. scanf("%d", &choice);
  140. switch (choice)
  141. {
  142. case 1:
  143. break;
  144. case 2:
  145. break;
  146. case 3:
  147. break;
  148. case 4:
  149. break;
  150. case 5:
  151. if(head->count==0)
  152. printf("\t\tqueue is empty\n");
  153. else
  154. printf("\t\tqueue is not empty\n");
  155. break;
  156. case 6:
  157. break;
  158. case 7:
  159. break;
  160. case 8:
  161. free(temp);
  162. free(node);
  163. free(head);
  164. return EXIT_SUCCESS;
  165. default:
  166. printf("\t\tplease only press 1 to 8\n");
  167. break;
  168. }
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement