In this lesson, we introduce the doubly linked list data structure and code up an implementation of this data structure in Python.
After that, we look at how to append (add elements to the back of the doubly linked list) and prepend (add elements to the front of the doubly linked list).
Finally, we will write a print method to verify that the append and prepend methods work as expected.
Doubly Linked List
Doubly Linked List
As you can see, the doubly linked list is very similar to the singly linked list except for the difference of the previous pointer. In a doubly linked list, a node is made up of the following components:
Data
Next (Points to the next node)
Prev (Points to the previous node)
As illustrated, the prev of the head node points to NULL while the next of the tail node also points to NULL.
Let’s go ahead and implement the Doubly Linked List in Python: