4 ms·
but that is not a puzzle, it's real code if you don't access to a collection library
by boomzilla 14y ago
but that is not a puzzle, it's real code if you don't access to a collection library
- jdmichal 14y agoNo, it's a puzzle for two reasons: 1. It's not a normal operation for a linked list. A normal linked list will expose operations to deal with items, not nodes. 2. There was an expected answer, and that answer was something other than the normal linked list delete operation of "traverse the list to find the node containing the item, while also keeping a trailing pointer to the previous item so that you can remove that item's node." Even if you are exposing nodes, and you do implement the given operation, then TheCoelacanth is absolutely correct that that operation just invalidated all references to the node after the one you thought you had just deleted, but not any references to the node you thought you had deleted. (Though those references are now pointing to a different data instance.)