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,*previous;
- } data;
- data *head=NULL;
- data *tail=NULL;
- void enQueue(int x)
- {
- data *node=(data*)malloc(sizeof(data));
- node->a=x;
- node->next=NULL;
- node->previous=NULL;
- if(head==NULL)
- {
- head=node;
- tail=node;
- return;
- }
- node->previous=tail;
- tail->next=node;
- return;
- }
- int deQueue()
- {
- data *temp=head;
- int x;
- if(head==NULL)
- {
- printf("no data!/n");
- return -1;
- }
- else if(temp->next==NULL)
- {
- x=temp->a;
- free(temp);
- head=NULL;
- tail=NULL;
- return x;
- }
- head=temp->next;
- x=temp->a;
- free(temp);
- head->previous=NULL;
- return x;
- }
- void print()
- {
- data *temp=head;
- while(temp!=NULL)
- {
- printf("%d/n",temp->a);
- temp=temp->next;
- }
- printf("\n");
- }
- int main()
- {
- int n1,n2,n3,n4,i,x,max=-1;
- scanf("%d",&n1);
- for(i=0; i<n1; i++)
- {
- scanf("%d",&n2);
- enQueue(n2);
- }
- scanf("%d",&n3);
- for(i=0; i<n3; i++)
- {
- // scanf("%d",&n4);
- x=deQueue();
- if(max<x)
- {
- max=x;
- }
- }
- print();
- printf("max :%d/n",max);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement