Advertisement
afrinahoque

minimum in doubly

Dec 8th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 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.  
  9. node *head=NULL, *tail=NULL;
  10.  
  11. void insert_at_last()
  12. {
  13. node *N=(node*)malloc(sizeof(node));
  14. scanf("%d", &N->a);
  15. N->next=NULL;
  16.  
  17. if(head==NULL)
  18. {
  19. head=N;
  20. tail=N;
  21. return;
  22. }
  23. else
  24. {
  25. tail->next=N;
  26. N->prev=tail;
  27. }
  28. }
  29.  
  30. void min()
  31. {
  32. int min=0;
  33. node *list=head;
  34. if(head==NULL)
  35. {
  36. printf("This is Empty.\n");
  37. return;
  38. }
  39. else
  40. {
  41. while(list!=NULL)
  42. {
  43. if(list->a<min)
  44. {
  45. min=list->a;
  46. }
  47. list=list->next;
  48. }
  49. }
  50. printf("Min: %d\n", min);
  51. }
  52.  
  53. int main()
  54. {
  55. int i,x;
  56. for(i=1; i<=4; i++)
  57. {
  58. insert_at_last();
  59. }
  60. min();
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement