Skip to main content

Timeline for Linked list: removing first element

Current License: CC BY-SA 4.0

9 events
when toggle format what by license comment
Nov 28, 2019 at 10:48 comment added Joop Eggen Yes it is redundant, the life time analysis of objects takes care of that & more efficiently. As confirmation readers may upvote this comment.
Nov 28, 2019 at 8:23 comment added OverLordGoldDragon So can you (or anyone) confirm that setting to null is redundant, and happens automatically by the garbage collector? This is the main idea I'm trying to understand
Nov 27, 2019 at 16:05 comment added Joop Eggen My apology too. Though if the list contains one element last == first, and a removeFirst should null out last. The removed node, and neither its fields need not be nulled in garbage collected languages. It is bad style as it delivers noise to the code reader, and the code writer should better concentrate on functional code. For this reason I automatically just gave the most minimal code.
Nov 27, 2019 at 15:51 comment added OverLordGoldDragon @rolfl , J. Eggen I tried keeping the question minimal, but apparently the intent wasn't too clear - see updated. The most relevant part of this answer is the third bullet point - but is that all there's to say on it? If so, that's fair, but that's the point that should be discussed/emphasized - the rest of the answer's not really relevant (also last = null handling is incorrect per standard implementations, as removing from an empty list should throw an exception)
Nov 27, 2019 at 15:11 history edited Joop Eggen CC BY-SA 4.0
added 330 characters in body
Nov 27, 2019 at 14:24 comment added rolfl I like this answer, it addresses the core quesiton about having the (unnecessary) second variable, and it also resolves the issue with the possible dangling last pointer if first == last. It may need some better text to describe those aspects, but this is a review with good observations IMHO.
Nov 27, 2019 at 14:09 comment added Joop Eggen @OverLordGoldDragon setting fields/variables to null in order to help garbage collection faster saving memory, has almost no discernible gain (time gain in the future). As there is an extra assignment it might even be slower, I take it that a Node is not held outside of the list.
Nov 27, 2019 at 14:05 review Low quality posts
Nov 27, 2019 at 14:40
Nov 27, 2019 at 13:49 history answered Joop Eggen CC BY-SA 4.0