We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 6bff826 + 4eddeb9 commit 9b054f5Copy full SHA for 9b054f5
data_structures/Stacks/__init__.py
@@ -0,0 +1,23 @@
1
+class Stack:
2
+
3
+ def __init__(self):
4
+ self.stack = []
5
+ self.top = 0
6
7
+ def is_empty(self):
8
+ return self.top == 0
9
10
+ def push(self, item):
11
+ if self.top < len(self.stack):
12
+ self.stack[self.top] = item
13
+ else:
14
+ self.stack.append(item)
15
16
+ self.top += 1
17
18
+ def pop(self):
19
+ if self.is_empty():
20
+ return None
21
22
+ self.top -= 1
23
+ return self.stack[self.top]
0 commit comments