What is a sentinel node?

Sentinel nodes are specially designed nodes that do not hold or refer to any data of the doubly linked list (that data structure).

To make insertion and deletion operations in a doubly-linked list simple, we have to add one sentinel node at the beginning of the doubly linked list and one at the end of the doubly linked list, as shown in the below diagram.

Doubly linked list with sentinel nodes

As shown above, each node other than the sentinel nodes contains the pointer to the previous and next node along with data.

Doubly Linked List using Sentinel Nodes

In the case of the simple doubly linked list, if we have to perform the insertion or deletion operation at the starting of the doubly linked list, end of the doubly linked list, or in between the starting and end nodes for each, we require to check different condition that makes the algorithm complex so to solve this problem we can use doubly linked list along with the sentinel nodes.

Similar Reads

What is a sentinel node?

Sentinel nodes are specially designed nodes that do not hold or refer to any data of the doubly linked list (that data structure)....

Advantage of Sentinel node:

The most significant advantage of using the sentinel nodes in the doubly linked list:...

Structure of a Doubly-Linked List using sentinel nodes:

The structure of each node and the creation of the new node in a doubly-linked list with sentinel nodes are the same as the simple doubly-linked list, as shown below....

Operations on a doubly-linked list using Sentinel Nodes:

The common operations in a doubly-linked list are:...