Skip to main content

Section 5.3 Doubly Linked Lists

The singly linked list allows direct access from a list node solely to the next node in the list. On the other hand, a doubly linked list offers the convenience of accessing both the next and preceding nodes from a list node. This is achieved by including two pointers in each doubly linked list node: one pointing to the next node (similar to the singly linked list) and another pointing to the preceding node. The primary advantage of using a doubly linked list is its ease of implementation compared to a singly linked list. Although the code for the doubly linked implementation may be slightly longer than its singly linked counterpart, it tends to be more straightforward in its purpose, making it easier to implement and debug. It is important to note that the decision to use a doubly or singly linked list should be hidden from the user of the List class.
Similar to the implementation of our singly linked list, the doubly linked list implementation incorporates a header node. Additionally, we introduce a tailer node at the end of the list. The tailer node, like the header node, does not contain any value and is always present. During the initialization of the doubly linked list, the header and tailer nodes are created. The data member "head" points to the header node, and "tail" points to the tailer node. These nodes simplify the insert, append, and remove methods by eliminating the need for special-case code when the list is empty or when inserting at the head or tail of the list.
You have attempted of activities on this page.