#include<stdio.
h>
#include<conio.h>
struct node
         int num;
         struct node *next;
};
struct node *first,*cur,*prev;
void init()
         first=NULL;
         printf("\n first=%u",first);
void add_node()
         struct node *temp;
         int t,ch,pos,st,found=0;
         while(1)
                printf("\n\t Add menu\n1.Add at start\n2.Add the end\n3.Add at intermediate
position\n4.Exit");
                 scanf("%d",&ch);
                 switch(ch)
                          case 1: temp=(struct node*)malloc(sizeof(struct node));
                          printf("\nAddress of temp=%u",temp);
                          printf("\n Enter data: ");
                          scanf("%d",&t);
                         temp->num=t;
                   temp->next=first;
                   first=temp;
                   break;
                   case 2: temp=(struct node*)malloc(sizeof(struct node));
                   printf("\n Address of temp=%u",temp);
                   printf("\n Enter data");
                   scanf("%d",&t);
                   temp->num=t;
                   cur=first;
                   if(cur==NULL)
                            first=temp;
                   else
                            while(cur->next!=NULL)
                                     cur=cur->next;
                            cur->next=temp;
                   temp->next=NULL;
                   break;
                   case 3: printf("\n Enter the position after which you want to enter data: ");
                   scanf("%d",&pos);
                   st=1;
cur=first;
             while(cur->next!=NULL)
             {
                           if(st==pos)
                                    found =1;
                                    break;
                           else
                                    cur=cur->next;
                                    st++;
                  if(found==1)
                           temp=(struct node*)malloc(sizeof(struct node));
                           printf("\n Enter data: ");
                           scanf("%d",&t);
                           temp->num=t;
                           temp->next=cur->next;
                           cur->next=temp;
                  else
                  printf("\n Position out of range");
                  break;
                  case 4: return;
                  default: printf("\n\n Wrong Choice\n\n");
void del_node()
{
       struct node *temp;
       int t,ch,pos,st,found=0;
       while(1)
                  printf("\n\t Delete Menu\n1.Delete starting node\n2.Delete End Node\n3.Delete a
intermediate");
                  scanf("%d",&ch);
                  switch(ch)
                         case 1: if(first==NULL)
                                  printf("\n Empty list: nothing deleted");
                                  break;
                         temp=(struct node*)malloc(sizeof(struct node));
                         temp=first;
                         first=first->next;
                         printf("\nNode deleted");
                         free(temp);
                         break;
                         case 2: if(first==NULL)
                                  printf("\n Empty list:nothing deleted");
                                  break;
                         temp=(struct node*)malloc(sizeof(struct node));
                         cur=prev=first;
                         cur=cur->next;
                         while(cur->next!=NULL)
                        {
                                 prev=cur;
                                 cur=cur->next;
                        temp=cur;
                        prev->next=NULL;
                        printf("\n Node deleted");
                        free(temp);
                        break;
                        case 3: printf("\n Enter the position after which you want to delete node: ");
                        scanf("%d",&pos);
                        st=1;
                        cur=first;
                        while(cur->next!=NULL)
                                 if(st==pos)
                                          found=1;
                                          break;
                        case 4: return;
                        default: printf("\n\n Wrong choice\n\n");
void display()
        cur=first;
        if(cur==NULL)
        {
                 printf("\n Empty link!");
                 return;
       printf("\n Link list contents are:\n");
       do
                 prinft("%d\n",cur->num);
                 cur=cur->next;
       }while(cur!=NULL);
void main()
       int ch;
       init();
       while(1)
               printf("\n\t Main menu\n1.Add element \n2.Delete element\n3.Display
elements\n4.exit\nEnter choice");
                 scanf("%d",&ch);
                 switch(ch)
                           case 1: add_node();
                           break;
                           case 2: del_node();
                           break;
                           case 3: display();
                           break;
                           case 4: exit(0);
                           default: printf("\n\n Wrong choice\n\n");