DELETE OPERATION ON LINKED LIST

The delete operation on linked list can be done in 3 different positions .They are
At the beginning
In the middle
At the end
BEGINNING
The head pointer need to be moved to the next node,
head=head->next
END
use a dummy variable to store the head pointer
Move the dummy variable to last but one position node
then put the next variable of dummy variable to NULL
void delete_end()
{
struct node *dummy;
dummy=head;
while(dummy->next!=NULL)
dummy=dummy->next;
dummy->next=NULL;
}
In the middle
This function takes position as argument.The dummy variable is used to store the head variable , the head variable is moved until l-1 position then change the pointer next value is moved to next value of next variable.
void delete_at_middle(int l)
{
int i=0;
struct node *dummy;
dummy=head;
while(i
{
dummy=dummy->next;
i++;
}
dummy->next=dummy->next->next;
}
PRINT FUNCTION
void print()
{
struct node *dummy;
dummy=head;
while(dummy==NULL)
{
printf("%d",dummy->data);
dummy=dummy->next;
}
}
This is a print the values of linked list.
this function uses a dummy variable to store head variable and it is moved until it is NULL which means loop traverses through all the nodes and in this process value in the node can be printed.