Advertisement
mushratjahan

labquiz01

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