You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recall that in our example, target is a pointer to the item to be removed, not a pointer to the previous item to be searched, which doesn't even exist in case of removing the first item.
That works as long as the element is not last in the list. You are basically rewriting the target element to be the same as the next and then deleting the next one, so the result is that the target is deleted. If there is no next element, there is nothing to duplicate and delete. We need a pointer to the previous item in this case, which is what ckwastra pointed out, I think.
As knowing the node to remove, why traverse the linked list instead of doing something such as:
The text was updated successfully, but these errors were encountered: