Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- KB
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct Data
- {
- int a;
- struct Data *next,*prev;
- }Data;
- Data *head=NULL, *tail=NULL;
- void enQueue(int x)
- {
- Data *new_node=(Data*)malloc(sizeof(Data));
- new_node->a=x;
- new_node->next=NULL;
- new_node->prev=NULL;
- if(head==NULL)
- {
- head=new_node;
- tail=head;
- return;
- }
- new_node->prev=tail;
- tail->next=new_node;
- tail=new_node;
- }
- int deQueue()
- {
- Data *dlt=head;
- int x;
- if(head==NULL)
- {
- printf("Empty!\n");
- return -1;
- }
- else if(head->next==NULL)
- {
- head=NULL;
- tail=NULL;
- x = dlt -> a;
- free(dlt);
- return x;
- }
- head=head->next;
- head->prev=NULL;
- x = dlt -> a;
- free(dlt);
- return x;
- }
- void Print()
- {
- int x=0;
- Data *tmp=head;
- while(tmp!=NULL)
- {
- printf("%d. Enqueued Value: %d\n", ++x, tmp -> a);
- tmp=tmp->next;
- }
- }
- int main()
- {
- int i,n,DQ=0,max=0;
- float deQ,avr,sum=0;
- printf("Enter number of Enqueue: ");
- scanf("%d",&n);
- for(i=0;i<n;i++)
- {
- int vlu;
- printf("\nEnter Enqueue Value %d: ",i+1);
- scanf("%d",&vlu);
- enQueue(vlu);
- }
- Print();
- int j,m;
- printf("\nEnter number of Dequeue: ");
- scanf("%d",&m);
- if(m>n)
- {
- for(j=0;j<n;j++)
- {
- int deQ;
- deQ = deQueue();
- sum+=deQ;
- if(max<deQ)
- {
- max=deQ;
- }
- }
- Print();
- avr=sum/n;
- printf("\nAverage of Dequeued value: %.2f",avr);
- printf("\nMax of Dequeued value: %d",max);
- return 0;
- }
- for(j=0;j<m;j++)
- {
- int deQ;
- deQ = deQueue();
- sum+=deQ;
- if(max<deQ)
- {
- max=deQ;
- }
- }
- Print();
- avr=sum/m;
- printf("\nAverage of Dequeued value: %.2f",avr);
- printf("\nMax of Dequeued value: %d",max);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement