Structure of a singly linked list


A linked list is just a chain of nodes. Below is how these nodes chain together to form a singly linked list.

Loading Image

Logical representation of a singly linked list

When represented logically in a diagram, these nodes might look sequential (left to right, one after the other), but in reality, they are scattered all around in memory at random locations, and the only way to access a node is by using its address in memory.

Loading Image

Representation of singly linked list in memory

Head Node

The first node of a linked list is also called the head node. As we know, a node in the linked list can only be accessed using its memory reference. This reference, however, is stored in the node before it in the logical representation, and this is true for every node except the first node, as it does not have any previous node. This is why, to access a linked list, we should always have the reference to the head node stored somewhere. 

Loading Image

Head of a singly linked list

Tail Node

The last node of a linked list is called a tail node. Just like the first node does not have any node before it, the last node does not have any node after it. You may wonder what is stored in the next pointer of the tail node. The next pointer of the tail node stores a reference to null, which means nothing. As we will see later, this also helps us determine the end of the linked list.

Loading Image

Tail of a singly linked list

Login to save progress