Skip to content

Commit 75094da

Browse files
authored
Implement simple stack class in stack.py
**Title:** Add Stack Implementation in data_structures **Description:** This PR adds a simple Stack data structure implementation in Python to the `data_structures` directory. The class supports `push`, `pop`, and `is_empty` methods, with error handling for popping from an empty stack. Let me know if you would like me to add tests or further documentation.
1 parent a71618f commit 75094da

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

stack.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Example: Simple Stack implementation
2+
class Stack:
3+
def __init__(self):
4+
self.items = []
5+
6+
def push(self, item):
7+
self.items.append(item)
8+
9+
def pop(self):
10+
if not self.is_empty():
11+
return self.items.pop()
12+
raise IndexError("pop from empty stack")
13+
14+
def is_empty(self):
15+
return len(self.items) == 0

0 commit comments

Comments
 (0)