Sentinel node

In computer programming, a sentinel node is a specifically designated node used with linked lists and trees as a traversal path terminator.

Sentinels are used as an alternative over using NULL as the path terminator in order to get one or more of the following benefits: Below are two versions of a subroutine (implemented in the C programming language) for looking up a given search key in a singly linked list.

The declarations of the singly linked list data structure and the outcomes of both subroutines are the same.

The for-loop contains two tests (yellow lines) per iteration: The globally available pointer sentinel to the deliberately prepared data structure Sentinel is used as end-of-list indicator.

Note that the pointer sentinel has always to represent every leaf of the tree.