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 5ba74d9 commit 70f070aCopy full SHA for 70f070a
stack/stack.py
@@ -0,0 +1,30 @@
1
+class Stack:
2
+ def __init__(self):
3
+ self._data = []
4
+ self.size = 0
5
+
6
+ def push(self, value, *args):
7
+ self._data.append(value)
8
+ for item in args:
9
+ self._data.append(item)
10
+ self.size += 1
11
12
+ def pop(self):
13
+ self._data.pop(-1)
14
+ self.size -= 1
15
16
+ def peek(self):
17
+ return self._data[-1]
18
19
+ def printStack(self):
20
+ return ('[ ' + ', '.join(map(lambda item: str(item), self._data)) + ']')
21
22
+myStack = Stack();
23
+myStack.push(5)
24
+myStack.push(10)
25
+myStack.push(89)
26
+print("Peek:", myStack.peek())
27
+myStack.pop()
28
29
+print(myStack.printStack())
30
0 commit comments