SHARE
TWEET

Minimum in doubly

afrinahoque Dec 8th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         N->prev=tail;
  26.         tail->next=N;
  27.         tail=N;
  28.     }
  29. }
  30.  
  31. void min()
  32. {
  33.     int min;
  34.     node *list=head;
  35.     if(head==NULL)
  36.     {
  37.         printf("This is Empty.\n");
  38.         return;
  39.     }
  40.     else
  41.     {
  42.         while(list!=NULL)
  43.         {
  44.             if(list->a<min)
  45.             {
  46.                 min=list->a;
  47.             }
  48.             list=list->next;
  49.         }
  50.     }
  51.     printf("Min: %d\n", min);
  52. }
  53.  
  54. int main()
  55. {
  56.     int i,x;
  57.     for(i=1; i<=4; i++)
  58.     {
  59.         insert_at_last();
  60.     }
  61.     min();
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top