I have been studying data structures and there is a section on “Constructor and Adding to Head” under linked lists that I do not understand?
I am wondering why the step 4 ( Finally, still in your
.addToHead() method, check if there is a current head to the list. If there is, set the list’s head’s next node to
currentHead .) is needed.
Should the line “This.head = newHead” not be enough the make the newHead node the first node in the linked list ?
Please see the link below for further details