-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack2.py
More file actions
42 lines (33 loc) · 832 Bytes
/
Copy pathStack2.py
File metadata and controls
42 lines (33 loc) · 832 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
32
33
34
35
36
37
38
39
40
41
42
class Stack ():
def __init__(self):
self.items = { }
self.top = 0
def isEmpty (self):
return self.top == 0
def push (self, item):
self.top += 1
self.items[self.top] = item
def pop (self):
item = self.items[self.top]
self.top -= 1
return item
def peek (self):
return self.items[self.top]
def size (self):
return self.top
##################################################
def main():
print("Running Stack2.py")
myStack = Stack()
print(myStack.isEmpty())
myStack.push("cat")
myStack.push(4)
print(myStack.peek())
myStack.push(False)
print(myStack.size())
print(myStack.isEmpty())
myStack.push(98.6)
print(myStack.pop())
print(myStack.pop())
print(myStack.size())
main()