struct node
{
int data;
struct node *link;
};
void delet(struct node **currNode,int location)
{
int i;
struct node *temp,*temp1,*temp2;
int cnt;
temp= *currNode;
cnt=count(currNode);
if(location>cnt)
{
printf("\nIndex should be <= %d",cnt);
}
for(i=1;i<=cnt;i++)
{
if(location==1&&i==1)
{
*currNode=temp->link;
free(temp);
}
if(i==location-1)
{
temp1=temp->link;
temp->link=temp->link->link;
free(temp1);
}
temp=temp->link;
}
}
int count(struct node **currNode)
{
int count;
struct node *temp;
temp= *currNode;
if(*currNode==NULL)
{
count=0;
}
else
count=1;
while(temp->link!=NULL)
{
temp=temp->link;
count++;
}
return count;
}
void main()
{
int value,index;
struct node *currNode;
currNode=NULL;
printf("Enter Index : ");
scanf("%d",&value);
//delete node in the given index of a link list
delet(&currNode,value);
}