#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
     struct node *previous;
     int data;
     struct node *next;
}*head;

void insert_begning(int value)
{
     struct node *var;
     var=(struct node *)malloc(sizeof(struct node));
     var->data=value;
     if(head==NULL)
     {
         head=var;
         head->previous=NULL;
         head->next=NULL;
         
     }
     else
     {
         var->previous=NULL;
         var->next=head;
         head->previous=var;
         head=var;
     }
}

int insert_after(int value, int loc)
{
     struct node *temp,*var,*temp1;
     var=(struct node *)malloc(sizeof(struct node));
     var->data=value;
         if(head==NULL)
         {
           head=var;
           head->previous=NULL;
           head->next=NULL;
           
         }
         else
         {
           temp=head;
           while(temp!=NULL && temp->data!=loc)
           {
                 temp=temp->next;
           }
           if(temp==NULL)
           {
                printf("\n%d is not present in list ",loc);
           }
           else
           {
           temp1=temp->next;
           temp->next=var;
           var->previous=temp;
           var->next=temp1;
           if(temp1!=NULL)
           temp1->previous=var;
           }
        }
     
}
void display()
{
     struct node *temp;
     temp=head;
     if(temp==NULL)
      {
         printf("List is Empty");
      }
     while(temp!=NULL)
     {
          printf("-> %d ",temp->data);
          temp=temp->next;
     }
}

int main()
{
    int value, i, loc;
    head=NULL;
    printf("Select the choice of operation on link list");
    printf("\n1.) insert begning\n2.) insert after the value\n3.) exit\n");
    while(1)
    {
          printf("\n\nenter the choice of operation you want to do ");
          scanf("%d",&i);
          switch(i)
          {
                case 1:
                {
                 printf("enter the value you want to insert in node ");
                 scanf("%d",&value);
                 insert_begning(value);
                 display();
                 break;
                 }
                
                 case 2:
                 {
                 printf("after which data you want to insert data ");
                 scanf("%d",&loc);
                 printf("enter the data you want to insert in list ");
                 scanf("%d",&value);
                 insert_after(value,loc);
                 display();
                 break;
                 }
                 
                 case 3 :
                 {
                      exit(0);
                      break;
                 }
          }
    }
    
}