Advertisement
shakilsaad

enQueue

Feb 22nd, 2020
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct data
  4. {
  5.     int a;
  6.     struct data *next,*previous;
  7. } data;
  8. data *head=NULL;
  9. data *tail=NULL;
  10. void enQueue(int x)
  11. {
  12.     data *node=(data*)malloc(sizeof(data));
  13.     node->a=x;
  14.     node->next=NULL;
  15.     node->previous=NULL;
  16.     if(head==NULL)
  17.     {
  18.         head=node;
  19.         tail=node;
  20.         return;
  21.     }
  22.     node->previous=tail;
  23.     tail->next=node;
  24.     return;
  25.  
  26. }
  27.  
  28. int deQueue()
  29. {
  30.     data *temp=head;
  31.     int x;
  32.     if(head==NULL)
  33.     {
  34.         printf("no data!/n");
  35.         return -1;
  36.     }
  37.  
  38.     else if(temp->next==NULL)
  39.     {
  40.         x=temp->a;
  41.         free(temp);
  42.         head=NULL;
  43.         tail=NULL;
  44.         return x;
  45.  
  46.     }
  47.     head=temp->next;
  48.     x=temp->a;
  49.     free(temp);
  50.     head->previous=NULL;
  51.     return x;
  52.  
  53. }
  54. void print()
  55. {
  56.     data *temp=head;
  57.     while(temp!=NULL)
  58.     {
  59.         printf("%d/n",temp->a);
  60.         temp=temp->next;
  61.     }
  62.     printf("\n");
  63. }
  64. int main()
  65. {
  66.     int n1,n2,n3,n4,i,x,max=-1;
  67.     scanf("%d",&n1);
  68.     for(i=0; i<n1; i++)
  69.     {
  70.         scanf("%d",&n2);
  71.         enQueue(n2);
  72.  
  73.     }
  74.     scanf("%d",&n3);
  75.     for(i=0; i<n3; i++)
  76.     {
  77. //        scanf("%d",&n4);
  78.         x=deQueue();
  79.         if(max<x)
  80.         {
  81.             max=x;
  82.         }
  83.     }
  84.     print();
  85.     printf("max :%d/n",max);
  86.  
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement