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,*prev;
- }data;
- data *head=NULL;
- data *tail=NULL;
- void enqeue(int x)
- {
- data *new=(data*)malloc(sizeof(data));
- new->a=x;
- new->next=NULL;
- new->prev=NULL;
- if(head==NULL)
- {
- head=new;
- tail=head;
- return;
- }
- new->prev=tail;
- tail->next=new;
- tail=new;
- }
- int dequeue()
- {
- int x;
- data *temp=head;
- if(head==NULL)
- {
- printf("NOT FOUND\n");
- return -1;
- }
- else if(temp->next==NULL)
- {
- head=NULL;
- tail=NULL;
- x=temp->a;
- free(temp);
- return x;
- }
- head=temp->next;
- x=temp->a;
- free(temp);
- return x;
- }
- void print()
- {
- data *temp=head;
- while(temp!=NULL)
- {
- printf("%3d\n",temp->a);
- temp=temp->next;
- }
- printf("\n");
- return;
- }
- int main()
- {
- int a1,a2,a3,a4,i,max=-1;
- scanf("%d",&a1);
- for(i=0;i<a1;i++)
- {
- scanf("%d",&a2);
- enqeue(a2);
- }
- scanf("%d",&a3);
- for(i=0;i<a3;i++)
- {
- // scanf("%d",&a4);
- int x;
- x=dequeue();
- if(max<x)
- {
- max=x;
- }
- }
- print();
- printf("Max: %d\n",max);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement