SAADQUAMER

Doubly_max

Oct 29th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct node
  5. {
  6.  
  7. int a;
  8. struct node*next;
  9. struct node*previous;
  10. } node;
  11. node*head;
  12.  
  13. void display()
  14. {
  15.  
  16. node*list=head;
  17.  
  18.  
  19. int k=list->a;
  20.  
  21. while(list!=NULL)
  22. {
  23.  
  24. if(k<list->a)
  25. {
  26. k=list->a;
  27. }
  28.  
  29. list=list->next;
  30. }
  31. printf("\nMAX VALUE IS : %d\n",k);
  32. }
  33.  
  34. void insert_at_end(int aN)
  35. {
  36.  
  37. node*N=(node*)malloc(sizeof(node));
  38. N->a=aN;
  39. N->next=NULL;
  40. N->previous=NULL;
  41. node*list=head;
  42. if(head==NULL)
  43. {
  44. head=N;
  45. }
  46. else
  47. {
  48. while(list->next!=NULL)
  49. {
  50. list=list->next;
  51. N->previous=list;
  52. }
  53. list->next=N;
  54. N->next=NULL;
  55. N->previous=list;
  56.  
  57.  
  58. }
  59.  
  60. }
  61.  
  62. int main()
  63. {
  64. int i,x,af,l;
  65. head=NULL;
  66. printf("ENTER TOTAL INPUT :");
  67. scanf("%d",&l);
  68. for(i=0; i<l; i++)
  69. {
  70. scanf("%d",&af);
  71. insert_at_end(af);
  72. }
  73.  
  74.  
  75. display();
  76.  
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment