-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
38 lines (29 loc) · 767 Bytes
/
stack.py
File metadata and controls
38 lines (29 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Stack:
def __init__(self):
self.stack = []
# Insert item on top of the stack (end of array)
def appendItem(self, value):
self.stack.append(value)
# Remove item on top of the stack (end of array)
def popItem(self):
return self.stack.pop()
# Prints the items inside the stack
def printStack(self):
for index in reversed(range(-1, len(self.stack)+1)):
if index == -1:
print("-------bottom------")
elif index == len(self.stack):
print("--------Top--------")
else:
print(" " + str(self.stack[index]) + " ")
def size(self):
return len(self.stack)
def main():
myStack = Stack()
myStack.appendItem(1)
myStack.appendItem(2)
myStack.appendItem(3)
myStack.printStack()
print(myStack.popItem())
myStack.size()
main()