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 aN)
- {
- node*N=(node*)malloc(sizeof(node));
- N->a=aN;
- N->next=NULL;
- N->prev=NULL;
- if(head==NULL)
- {
- head=N;
- tail=N;
- return;
- }
- else
- {
- tail->next=N;
- N->prev=tail;
- N->next=NULL;
- tail=N;
- return;
- }
- }
- int POP()
- { int a=0;
- node*list;
- if(head==NULL)
- {
- printf("empty");
- }
- else
- {
- node* temp;
- temp=tail;
- a=tail->a;
- tail->prev->next=NULL;
- tail = tail->prev;
- free(temp);
- return a;
- }
- }
- int main()
- {
- int n,x,y,i,j,s=0;
- printf("ENTER PUSH CASE:");
- scanf("%d",&n);
- for(i=0; i<n; i++)
- {
- scanf("%d",&x);
- PUSH(x);
- }
- printf("ENTER POP CASE:");
- scanf("%d",&y);
- for(j=0; j<y; j++)
- {
- s=POP();
- printf("%d ",s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement