Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<limits.h>
- struct queue
- {
- int data;
- struct queue *next;
- }*rear=NULL,*front=NULL;
- int size=0;
- int main()
- {
- int data,choice;
- while(1)
- {
- printf("1: Enqueue \n");
- printf("2: Dequeue \n");
- printf("3: Show The Number of Item\n");
- printf("4: Minimum And Maximum items\n");
- printf("5: Find An Item\n");
- printf("6: Print All Item\n");
- printf("0: Exit\n");
- printf(" \nSelect your option: ");
- scanf("%d",&choice);
- switch(choice)
- {
- case 1:
- printf("Enter data to Enqueue: ");
- scanf("%d",&data);
- enqueue(data);
- break;
- case 2:
- dequeue();
- break;
- case 3:
- printf("The Number of item is %d",size);
- break;
- case 4:
- minmax();
- break;
- case 5:
- find();
- break;
- case 6:
- displayList();
- break;
- case 0:
- printf("Exiting from terminal\n");
- exit(0);
- }
- printf("\n\n");
- }
- }
- void enqueue(int data)
- {
- struct queue *temp;
- temp=(struct queue *)malloc(sizeof(struct queue));
- temp->data=data;
- temp->next=NULL;
- if(front==NULL)
- {
- front=temp;
- rear=temp;
- }
- else
- {
- rear->next=temp;
- rear=temp;
- }
- printf("%d enqueued\n",temp->data);
- size++;
- }
- void dequeue()
- {
- struct queue *temp;
- int data;
- if(size<= 0 || !front)
- {
- printf("Queue is Empty");
- }
- temp=front;
- data=temp->data;
- front=front->next;
- free(temp);
- size--;
- printf("%d Dequeued",data);
- return 0;
- }
- void displayList()
- {
- struct queue *temp;
- temp=front;
- while(temp!= NULL)
- {
- printf("\n%d",temp->data);
- temp=temp->next;
- }
- }
- void minmax()
- {
- struct queue *temp;
- int max,min;
- temp=front;
- max=temp->data;
- min=temp->data;
- while(temp!=NULL)
- {
- if(temp->data>max)
- {
- max=temp->data;
- }
- if(temp->data<min)
- {
- min=temp->data;
- }
- temp=temp->next;
- }
- printf("Maximum element is : %d\n",max);
- printf("Minimum element is : %d\n",min);
- }
- void find()
- {
- struct queue *temp;
- int num,i,Item;
- i=0;
- temp=front;
- printf("Enter a number to find: ");
- scanf("%d",&num);
- while(temp!=NULL)
- {
- if(temp->data==num)
- {
- i++;
- Item=temp->data;
- }
- temp=temp->next;
- }
- printf("%d Found %d times\n",Item,i);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement