//insert node at any position
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
int info,item;
struct node *link;
};
struct node *prev,*n,*first,*this1;
int main()
{
char ch;
int item;
clrscr();
first=NULL;
printf(“Enter q to quite: “);
while((ch=getche())!=’q’)
{
n=(struct node*)malloc(sizeof(struct node));
printf(“\nEnter info= “);
scanf(“%d”,&n->info);
n->link=NULL;
if(first==NULL)
first=n;
else
{
this1=first;
while(this1->link!=NULL)
this1=this1->link;
this1->link=n;
}
printf(“Enter q to quite: “);
}
this1=first;
printf(“\nTraversing of linklist:”);
while(this1!=NULL)
{
printf(“\n%d”,this1->info);
this1=this1->link;
}
printf(“\nEntrer item before which new element is to be inserted: “);
scanf(“%d”,&item);
n=(struct node*)malloc(sizeof (struct node));
printf(“\nEnter the info of new node: “);
scanf(“%d”,&n->info);
if(item==first->info)
{
n->link=first;
first=n;
}
else
{
this1=first;
while(this1!=NULL&&this1->info!=item)
{
prev=this1;
this1=this1->link;
}
if(this1==NULL)
printf(“item not found: “);
else
{
n->link=this1;
prev->link=n;
}
}
this1=first;
printf(“Traversing After insert node:”);
while(this1!=NULL)
{
printf(“\n%d”,this1->info);
this1=this1->link;
}
getch();
return 0;
}