Hey I was trying to write a function in C to delete a node(only from the middle) from a Singly Linked List. I wrote one but not sure if the code will work fine under all test conditions. I have tested it and shows no error so far, but can you help me figure out any problems/issues that might arise if i used it that i have missed?
Code:
void deleteAt(struct node *root, int number){
while(root->link != NULL)
{
if(root->link->item == number) //checks if the next node is the element to be deleted
{
root->link = root->link->link; //points the link of the element to be deleted to the element before the element to be deleted
}
else
root = root->link;
}
}
Or is there a better way to do this?