Question

Consider a delete_node(head, key) function for a singly linked list that removes the first occurrence of a node with a given key. The function works for most cases but throws a NullPointerException (or equivalent in other languages) when attempting to delete the last node in a list of two or more nodes. Which of the following is a common oversight that could lead to this specific bug?

A Not handling the case where the head itself needs to be deleted.
B Failing to update the next pointer of the *previous* node to None when the target node is the last.
C Incorrectly traversing the list using current = current.next without checking current for None.
D Not checking if the list is empty before starting the deletion process.
E Forgetting to free the memory of the deleted node.
Practice Next

Hey! Ask a query