A head pointer is a reference to the first node in a linked list. In a singly linked list, the head node has no predecessor, so the list stores its reference separately. Setting the head to None represents an empty list. section 6.4 section 6.6
The head pointer gives several list operations their practical behavior:
- Accessing the head is constant time because the list already stores its reference. section 6.24
- Inserting before the head updates the stored reference to the new node. section 6.24
- Deleting the head updates the pointer to the removed node’s successor; this is also constant time. section 6.10 section 6.9
- Deleting another node requires traversing from the head while retaining its predecessor, because singly linked nodes only point forward. section 6.9
An empty Python list
A singly linked list can begin with no first node: class SinglyLinkedList: def __init__(self): self._head = None. Adding a first node later means changing _head to reference that node. section 6.6
class SinglyLinkedList:
def __init__(self):
self._head = None
Inspect the minimal Python initialization that stores the head reference and represents an empty list with None. section 6.6
