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.
1 parent 7b4356d commit 75ac338Copy full SHA for 75ac338
stack_using_array.py
@@ -0,0 +1,40 @@
1
+from sys import maxsize
2
+
3
4
+def createStack():
5
+ stack = []
6
+ return stack
7
8
9
+def isEmpty(stack):
10
+ return len(stack) == 0
11
12
13
+def push(stack, data):
14
+ stack.append(data)
15
+ print(data, "pushed to stack")
16
17
18
+def pop(stack):
19
+ if isEmpty(stack):
20
+ return str(-maxsize - 1)
21
22
+ return stack.pop()
23
24
25
+def peek(stack):
26
27
28
+ else:
29
+ return stack[len(stack) - 1]
30
31
32
+stack = createStack()
33
+push(stack, 10)
34
+push(stack, 20)
35
+push(stack, 30)
36
+print(stack)
37
+pop(stack)
38
39
+print(peek(stack))
40
+print(isEmpty(stack))
0 commit comments