Advertisement
SAADQUAMER

sam

Oct 19th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct node
  4. {
  5.     int a;
  6.     struct node *next,*prev;
  7. } node;
  8. node*head=NULL,*tail=NULL;
  9. void PUSH(int aN)
  10. {
  11.     node*N=(node*)malloc(sizeof(node));
  12.     N->a=aN;
  13.     N->next=NULL;
  14.     N->prev=NULL;
  15.  
  16.     if(head==NULL)
  17.     {
  18.         head=N;
  19.         tail=N;
  20.         return;
  21.     }
  22.     else
  23.     {
  24.         tail->next=N;
  25.         N->prev=tail;
  26.         N->next=NULL;
  27.         tail=N;
  28.         return;
  29.     }
  30.  
  31. }
  32.  
  33. int POP()
  34. { int a=0;
  35.     node*list;
  36.     if(head==NULL)
  37.     {
  38.         printf("empty");
  39.     }
  40.     else
  41.     {
  42.         node* temp;
  43.         temp=tail;
  44.         a=tail->a;
  45.         tail->prev->next=NULL;
  46.         tail = tail->prev;
  47.         free(temp);
  48.         return a;
  49.  
  50.     }
  51. }
  52. int main()
  53. {
  54.     int n,x,y,i,j,s=0;
  55.     printf("ENTER PUSH CASE:");
  56.     scanf("%d",&n);
  57.     for(i=0; i<n; i++)
  58.     {
  59.         scanf("%d",&x);
  60.         PUSH(x);
  61.     }
  62.    printf("ENTER POP CASE:");
  63.     scanf("%d",&y);
  64.     for(j=0; j<y; j++)
  65.     {
  66.         s=POP();
  67.         printf("%d ",s);
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement