File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 11# Complete Python program demonstrating stack operations using a doubly linked list
22from __future__ import annotations
33
4+
45class 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+
1114class 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
9195if __name__ == "__main__" :
9296 stack : Stack [int ] = Stack () # Create integer stack
You can’t perform that action at this time.
0 commit comments