Skip to content

Commit 98a5a16

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 8381edf commit 98a5a16

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

data_structures/stacks/stack_with_doubly_linked_list.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
# Complete Python program demonstrating stack operations using a doubly linked list
22
from __future__ import annotations
33

4+
45
class Node[T]:
56
"""Node class for doubly linked list"""
7+
68
def __init__(self, data: T):
79
self.data = data # Node data
810
self.next: Node[T] | None = None # Reference to next node
911
self.prev: Node[T] | None = None # Reference to previous node
1012

13+
1114
class Stack[T]:
1215
"""
1316
Stack implementation using doubly linked list
14-
17+
1518
>>> stack = Stack()
1619
>>> stack.is_empty()
1720
True
@@ -54,7 +57,7 @@ def pop(self) -> T | None:
5457
"""Pop element from top of stack"""
5558
if self.head is None:
5659
return None
57-
60+
5861
# Remove and return head node data
5962
temp = self.head.data
6063
self.head = self.head.next
@@ -87,6 +90,7 @@ def print_stack(self) -> None:
8790
print(current.data, end="->")
8891
current = current.next
8992

93+
9094
# Program entry point
9195
if __name__ == "__main__":
9296
stack: Stack[int] = Stack() # Create integer stack

0 commit comments

Comments
 (0)