Linkedlist head node | Sololearn: Learn to code for FREE!


Linkedlist head node

I still kind of get confused with head nodes. If you were to create a new node ‘Node temp’ and set it equal to the head node, would temp equal the node after head? Cause head is null by default I believe. I thought to loop over a linked list, the first iteration has to be (’s value) because head is null. Can clear my confusion?

11/15/2019 4:05:27 PM

Jamie Charles

3 Answers

New Answer


In a LinkedList you normally save the first Node of the List as head to have an entry point. When the list is empty you can set head of null. So before you iterate through a LinedList you should check if head is null first. I would recomment to make a Node (named p for example) to iterate through the list if head is not null. To get the value, a node normally has an attribute "value" and a connection to the next node with "next". If next is null you reached the end of the linked list.


You can make a while loop for example: Node p = head; while (p != null){ .... do your stuff.... p =; }


Jamie Charles Please take a look at this little Tutorial Regards kiuziu