Skip to content

Commit 15066f5

Browse files
📝 Doubly Linked List class
1 parent fb31d28 commit 15066f5

File tree

1 file changed

+26
-1
lines changed
  • 03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list

1 file changed

+26
-1
lines changed

03_data_structures/02_linked_list/02_linked_list/02_doubly_linked_list/readme.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,29 @@ class Node:
8686
* Points to the **previous node** in the list (the one to the left in diagrams).
8787
* A brand-new node has **no predecessor**, so `prev=None`.
8888

89-
---
89+
---
90+
91+
---
92+
93+
# **Doubly Linked List class**
94+
95+
In a **doubly linked list**, each node knows both its **next** and **previous** neighbor. To append (add to the end), we update:
96+
97+
1. The current **tail**’s `.next` → new node
98+
2. The new node’s `.prev` → old tail
99+
3. The list’s **tail** pointer → new node
100+
4. Increase the **count**
101+
102+
---
103+
104+
## 📜 Code for `DoublyLinkedList class`
105+
106+
```python
107+
class DoublyLinkedList:
108+
def __init__(self):
109+
self.head = None # First node
110+
self.tail = None # Last node
111+
self.count = 0 # Number of nodes
112+
113+
```
114+
---

0 commit comments

Comments
 (0)