Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- struct Node
- {
- int data;
- struct Node *next;
- } *temp,*temp2, *node;
- struct Head
- {
- int count;
- struct Node *first;
- struct Node *last;
- } *head;
- void Head_create()
- {
- head = (struct Head*) malloc(sizeof(struct Head));
- head->count = 0;
- head->first = NULL;
- head->last = NULL;
- }
- void Enque(int value)
- {
- node=(struct Node*)malloc(sizeof(struct Node));
- node->data = value;
- node->next=NULL;
- if(head->count==0)
- {
- head->first=node;
- head->last=node;
- (head->count)++;
- }
- else
- {
- head->last->next=node;
- head->last=node;
- (head->count)++;
- }
- }
- void Deque()
- {
- //temp=head->first;
- if(head->count == 0)
- printf("\t\tqueue is empty.\n");
- else if(head->count == 1)
- {
- temp=head->first;
- temp2=head->last;
- head->last=NULL;
- head->first=NULL;
- free(temp);
- free(temp2);
- (head->count)--;
- }
- else
- {
- temp=head->first;
- head->first=head->first->next;
- (head->count)--;
- free(temp);
- }
- }
- void Search_values(int value)
- {
- int flag = 0,i;
- for(temp = head->first,i=1; temp != NULL; temp = temp->next,i++)
- {
- if(temp->data == value)
- {
- printf("\t\t%d Found in the queue in %d th position.\n",temp->data,i);
- flag=1;
- break;
- }
- }
- if(flag == 0)
- {
- printf("\t\t%d not Found in the queue!\n",value);
- }
- }
- void Show_values()
- {
- temp = head->first;
- if(head->count==0)
- printf("\t\tNo values in the queue!!\n");
- else{
- printf("\t\tCurrent Values in the queue\n");
- while(temp != NULL)
- {
- printf("\t\t-> %d",temp->data);
- temp = temp->next;
- }
- }
- }
- void Rear()
- {
- if(head->count!=0)
- {
- printf("\t\tRear is: %d",head->last->data);
- }
- else
- printf("\t\tqueue is empty.\n");
- }
- void Front()
- {
- if(head->count!=0)
- {
- printf("\t\tFront is: %d",head->first->data);
- }
- else
- printf("\t\tqueue is empty.\n");
- }
- void Menu_function()
- {
- }
- int Take_number()
- {
- int value;
- printf("\t\tEnter a value: ");
- scanf("%d", &value);
- return value;
- }
- int main()
- {
- int choice;
- Head_create();
- for( ; ; )
- {
- Menu_function();
- scanf("%d", &choice);
- switch (choice)
- {
- case 1:
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- if(head->count==0)
- printf("\t\tqueue is empty\n");
- else
- printf("\t\tqueue is not empty\n");
- break;
- case 6:
- break;
- case 7:
- break;
- case 8:
- free(temp);
- free(node);
- free(head);
- return EXIT_SUCCESS;
- default:
- printf("\t\tplease only press 1 to 8\n");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement