My understanding is.
If the head is null, the list is empty. If the tail is null, we have reached the end of the list.
So, my question is,
In a LinkedList a-b-c-d-null
can either a b c and d be null elements?
Follow Up: In Java, is it mandatory for a Linked List to end in a null node?
CodePudding user response:
No, because if a node is null
then it doesn't store information about the next node in the list. This means that there are no references to nodes past the null
node, and in a language like Java (seen as though you tagged this post with the java
tag) they'd be garbage collected.