Circular lists
A circular linked list is a special case of a linked list. In a circular linked list, the endpoints are connected, which means that the last node in the list points back to the first node. In other words, we can say that in circular linked lists, all the nodes point to the next node (and the previous node in the case of a doubly linked list) and there is no end node, meaning no node will point to None
.
The circular linked lists can be based on both singly and doubly linked lists. Consider Figure 4.29 for the circular linked list based on a singly linked list where the last node, C, is again connected to the first node A, thus making a circular list.
Figure 4.29: Example of a circular list based on a singly linked list
In the case of a doubly linked circular list, the first node points to the last node, and the last node points back to the first node. Figure 4.30 shows the concept of the circular linked list based on a doubly linked list where the last...