Advertisement
Mostafiz543

Doubly list

Oct 14th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. #include<stdlib.h>
  4.  
  5. typedef struct node
  6.  
  7. {
  8.  
  9.     int a;
  10.  
  11.     char s[20];
  12.  
  13.     struct node *next;
  14.  
  15.     struct node *prev;
  16.  
  17. } node;
  18.  
  19. node *head=NULL,*tail=NULL;
  20.  
  21. void displaylst()
  22.  
  23. {
  24.  
  25.     int ch;
  26.  
  27.     node *list=tail;
  28.  
  29.     if(head==NULL)
  30.  
  31.     {
  32.  
  33.         printf("NO Data Available!!\n\n ");
  34.  
  35.     }
  36.  
  37.     else
  38.  
  39.     {
  40.  
  41.         while(list!=NULL)
  42.  
  43.         {
  44.  
  45.             printf("\nName: %s\n",list->s);
  46.  
  47.             printf("Age: %d\n\n",list->a);
  48.  
  49.             list=list->prev;
  50.  
  51.         }
  52.  
  53.     }
  54.  
  55.     printf("         1.Menu\n");
  56.  
  57.     printf("         2.Exit\n");
  58.  
  59.     printf("Press Any Option:");
  60.  
  61.     scanf("%d",&ch);
  62.  
  63.     switch(ch)
  64.  
  65.     {
  66.  
  67.     case 1:
  68.  
  69.     {
  70.  
  71.         menu();
  72.  
  73.     }
  74.  
  75.     case 2:
  76.  
  77.     {
  78.  
  79.         exit(0);
  80.  
  81.     }
  82.  
  83.  
  84.  
  85.     default:
  86.  
  87.     {
  88.  
  89.  
  90.  
  91.         printf("You Choose Wrong Option!!\a\n\n");
  92.  
  93.         menu();
  94.  
  95.         break;
  96.  
  97.     }
  98.  
  99.  
  100.  
  101.     }
  102.  
  103. }
  104.  
  105.  
  106.  
  107. void displayfrst()
  108.  
  109. {
  110.  
  111.     int ch;
  112.  
  113.     node *list=head;
  114.  
  115.     if(head==NULL)
  116.  
  117.     {
  118.  
  119.         printf("  NO Data Available!!\n\n ");
  120.  
  121.     }
  122.  
  123.     else
  124.  
  125.     {
  126.  
  127.         while(list!=NULL)
  128.  
  129.         {
  130.  
  131.             printf("\nName: %s\n",list->s);
  132.  
  133.  
  134.  
  135.             printf("Age: %d\n\n",list->a);
  136.  
  137.             list=list->next;
  138.  
  139.         }
  140.  
  141.     }
  142.  
  143.     printf("         1.Menu\n");
  144.  
  145.     printf("         2.Exit\n");
  146.  
  147.     printf("Press Any Option:");
  148.  
  149.     scanf("%d",&ch);
  150.  
  151.     switch(ch)
  152.  
  153.     {
  154.  
  155.     case 1:
  156.  
  157.     {
  158.  
  159.         menu();
  160.  
  161.     }
  162.  
  163.     case 2:
  164.  
  165.     {
  166.  
  167.         exit(0);
  168.  
  169.     }
  170.  
  171.  
  172.  
  173.     default:
  174.  
  175.     {
  176.  
  177.  
  178.  
  179.         printf("You Choose Wrong Option!!\a\n\n");
  180.  
  181.         menu();
  182.  
  183.         break;
  184.  
  185.     }
  186.  
  187.  
  188.  
  189.     }
  190.  
  191. }
  192.  
  193.  
  194.  
  195. void display()
  196.  
  197. {
  198.  
  199.     int ch,n;
  200.  
  201.     printf("       1.Display 1st To Last\n");
  202.  
  203.     printf("       2.Display Last To 1st\n");
  204.  
  205.     printf("Choose Any Option:");
  206.  
  207.     scanf("%d",&n);
  208.  
  209.     switch(n)
  210.  
  211.     {
  212.  
  213.     case 1:
  214.  
  215.     {
  216.  
  217.         displayfrst();
  218.  
  219.         break;
  220.  
  221.     }
  222.  
  223.     case 2:
  224.  
  225.     {
  226.  
  227.         displaylst();
  228.  
  229.         break;
  230.  
  231.     }
  232.  
  233.     default:
  234.  
  235.     {
  236.  
  237.         printf("You Choose Wrong Option!!\a\n\n");
  238.  
  239.         menu();
  240.  
  241.         break;
  242.  
  243.     }
  244.  
  245.     }
  246.  
  247. }
  248.  
  249. void searchpos()
  250.  
  251. {
  252.  
  253.     int ch,n;
  254.  
  255.     node *list=head;
  256.  
  257.     printf("Enter Your Position:");
  258.  
  259.     scanf("%d",&n);
  260.  
  261.     if(n==1)
  262.  
  263.     {
  264.  
  265.         printf("Name: %s\n",list->s);
  266.  
  267.         printf("Age: %d\n\n",list->a);
  268.  
  269.     }
  270.  
  271.     else
  272.  
  273.     {
  274.  
  275.         n=n-2;
  276.  
  277.         while(n!=0&&list->next!=NULL)
  278.  
  279.         {
  280.  
  281.             list=list->next;
  282.  
  283.             n--;
  284.  
  285.         }
  286.  
  287.         if(list->next==NULL)
  288.  
  289.         {
  290.  
  291.             printf("No Information Available!!\n\n");
  292.  
  293.         }
  294.  
  295.         else
  296.  
  297.         {
  298.  
  299.             printf("Name: %s\n",list->next->s);
  300.  
  301.             printf("Age: %d\n\n",list->next->a);
  302.  
  303.         }
  304.  
  305.     }
  306.  
  307.     printf("         1.Menu\n");
  308.  
  309.     printf("         2.Exit\n");
  310.  
  311.     printf("Press Any Option:");
  312.  
  313.     scanf("%d",&ch);
  314.  
  315.     switch(ch)
  316.  
  317.     {
  318.  
  319.     case 1:
  320.  
  321.     {
  322.  
  323.         menu();
  324.  
  325.     }
  326.  
  327.     case 2:
  328.  
  329.     {
  330.  
  331.         exit(0);
  332.  
  333.     }
  334.  
  335.  
  336.  
  337.     default:
  338.  
  339.     {
  340.  
  341.  
  342.  
  343.         printf("You Choose Wrong Option!!\a\n\n");
  344.  
  345.         menu();
  346.  
  347.         break;
  348.  
  349.     }
  350.  
  351.  
  352.  
  353.     }
  354.  
  355. }
  356.  
  357.  
  358.  
  359. void searchval()
  360.  
  361. {
  362.  
  363.     node *list=head;
  364.  
  365.     int ch,v;
  366.  
  367.     
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement