Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct Node{
- int data;
- struct Node *next;
- }*node,*temp;
- struct Head{
- int count;
- struct Node *front,*rear;
- }*head;
- void create_queue()
- {
- head=(struct Head*)malloc(sizeof(struct Head));
- head->count=0;
- head->front=NULL;
- head->rear=NULL;
- }
- void first_node()
- {
- node=(struct Node*)malloc(sizeof(struct Node));
- printf("Plz input data in QueUe\n");
- scanf("%d",&node->data);
- node->next=NULL;
- head->front=node;
- head->rear=node;
- head->count++;
- }
- void Enqueue()
- {
- node=(struct Node*)malloc(sizeof(struct Node));
- printf("Plz input data in QueUe\n");
- scanf("%d",&node->data);
- node->next=NULL;
- head->rear->next=node;
- head->rear=node;
- head->count++;
- }
- void Dequeue()
- {
- temp=head->front;
- head->front=temp->next;
- printf("%d is delated from Queue\n",temp->data);
- free(temp);
- head->count--;
- }
- void show()
- {
- int i;
- temp=head->front;
- for( i=0;i<head->count;i++)
- {
- printf("%d",temp->data);
- temp=temp->next;
- }
- }
- int main()
- {
- int i;
- while(1)
- {
- printf("Select ur Choice");
- printf("Press 1 to create queue");
- printf("Press 2 For Enqueue");
- printf("Press 3 For Dequeue");
- switch(i){
- case 1:
- {
- if(head->count==0){
- create_queue();
- }
- else
- printf("Al ready Queue is Created/Exist\n");
- break;
- }
- case 2:
- {
- if(head->count>=1){
- Enqueue();
- }
- else
- printf("First Create a queue\n");
- break;
- }
- case 3:
- {
- if(head->count>=1){
- Dequeue();
- }
- else
- printf("First Insert data in Queue\n");
- break;
- }
- default:
- printf("Wrong Choice.PLz select Right option\n");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement