Skip to content

Commit 8b2c01f

Browse files
committed
Stack implementation
1 parent 4557474 commit 8b2c01f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: stack_impl.py

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ def __init__(self):
77
self.items = []
88

99
def stack_length(self):
10+
"""
11+
Finds length of the given stack
12+
"""
1013
l = len(self.items)
1114
if not self.items:
1215
return "Empty Stack"
@@ -17,10 +20,16 @@ def stack_length(self):
1720
pass
1821

1922
def push(self, value):
23+
"""
24+
Push value to the stack
25+
"""
2026
self.items.append(value)
2127
return self.items
2228

2329
def pop(self):
30+
"""
31+
Pops element from the stack
32+
"""
2433
if not self.items:
2534
return None
2635
else:
@@ -35,6 +44,9 @@ def peek(self):
3544
return self.items[-1]
3645

3746
def min_element(self, stack_values):
47+
"""
48+
Returns the smallest element in the stack
49+
"""
3850
self.items = stack_values
3951
if not self.items:
4052
print("Empty Stack")

0 commit comments

Comments
 (0)