Will this below logic work for deleting a node in double linked list in c?
struct list *prev;
struct list *next;
void delete(struct list *temp)
temp->prev->next = temp->next;
temp->next->prev = temp->prev;
Yes it will work for all nodes.
It will not work for head node, but works for other nodes.
it will not work for tail node, but works for other nodes.
it will not work for head and tail node, but works for other nodes.
if supplied node is head, then temp->prev->next will crash as we are dereferencing null value. same is the case with tail node, temp->next->prev will crash as temp->next is null, so dereferencing it will crash. but it works fine for other intermediate nodes.
Back To Top