Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct node
- {
- int a;
- struct node *next,*prev;
- }node;
- node*head=NULL,*tail=NULL;
- void PUSH(int a)
- {
- node*p=(node*)malloc(sizeof(node));
- p->a=a;
- p->next=NULL;
- p->prev=NULL;
- if(head==NULL)
- {
- head=p;
- tail=p;
- return;
- }
- tail->next=p;
- p->prev=tail;
- p->next=NULL;
- tail=p;
- }
- int POP()
- { node*list;
- if(head==NULL)
- {
- printf("empty");
- }
- else
- {
- int temp;
- temp=tail->a;
- list=tail;
- list->prev->next=NULL;
- tail=list->prev;
- list->prev=NULL;
- free(list);
- return temp;
- }
- }
- int main()
- {
- int n,x,y,i,s=0;
- scanf("%d",&n);
- for(i=0;i<n;i++)
- {
- scanf("%d",&x);
- PUSH(x);
- }
- scanf("%d",&y);
- for(i=0;i<y;i++)
- {
- s=POP();
- printf("%d ",s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement