Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct Data
- {
- int a;
- struct Data *next;
- struct Data *prev;
- } Data;
- Data*head=NULL;
- Data*tail=NULL;
- int max=-1;
- void enQueue(int x)
- {
- Data *temp=head;
- Data *newnode=(Data*)malloc(sizeof(Data));
- scanf("%d",&x);
- newnode->a=x;
- newnode->next=NULL;
- newnode->prev=NULL;
- if(head==NULL)
- {
- head=newnode;
- tail=newnode;
- return;
- }
- tail->next=newnode;
- newnode->prev=tail;
- tail=newnode;
- }
- int deQueue()
- {
- Data *temp=head;
- if(head==NULL)
- {
- printf("Empty\n");
- return;
- }
- if(temp->next==NULL)
- {
- if(max < temp -> a)
- {
- max=temp->a;
- }
- head=NULL;
- return;
- }
- head=head->next;
- if(max < temp -> a)
- {
- max=temp->a;
- }
- free(temp);
- }
- void print()
- {
- Data *temp=head;
- while(temp!=NULL)
- {
- printf("%d ",temp->a);
- temp=temp->next;
- }
- printf("\n");
- }
- int main()
- {
- int x,i,p,q;
- scanf("%d",&p);
- for(i=0; i<p; i++)
- {
- enQueue(i);
- }
- print();
- //printf("%d\n",p);
- scanf("%d",&x);
- for(i=0; i<x; i++)
- {
- deQueue();
- }
- //printf("%d\n",x);
- print();
- printf("MAX is %d\n",max);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement