Day 9
Day 9: Doubly Linked Lists - Implementation and Comparison
9/60 Days
Doubly Linked Lists - Implementation and Comparison #
Welcome to Day 9 of our 60 Days of Coding Algorithm Challenge! Today, we’ll explore doubly linked lists, implement one from scratch, and compare it with singly linked lists.
What is a Doubly Linked List? #
A doubly linked list is a type of linked list where each node contains data and two pointers:
- A pointer to the next node
- A pointer to the previous node
This bi-directional linking allows for more flexible operations, especially when traversing the list in reverse or deleting nodes.
Implementing a Doubly Linked List #
Let’s implement a doubly linked list with basic operations:
1class Node:
2 def __init__(self, data):
3 self.data = data
4 self.prev = None
5 self.next = None
6
7class DoublyLinkedList:
8 def __init__(self):
9 self.head = None
10 self.tail = None
11
12 def is_empty(self):
13 return self.head is …
Continue Reading
Sign up or log in to access the full lesson and all 60 days of algorithm content.