-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmystack.py
More file actions
45 lines (35 loc) · 768 Bytes
/
mystack.py
File metadata and controls
45 lines (35 loc) · 768 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
43
44
45
"""
Stack Operations:
1) isEmpty()
2) push()
3) pop()
4) peek()
5) size()
"""
class Stack(object):
def __init__(self):
self.items = []
def isEmpty(self):
return self.items == []
def push(self, item):
self.items.append(item)
def pop(self):
return self.items.pop()
def peek(self):
return self.items[len(self.items) - 1]
def size(self):
return len(self.items)
st = Stack()
print("Is the Stack Empty?", st.isEmpty())
st.push("BooBoo")
print(st.peek())
st.push(5.3)
print(st.peek())
print("The size of the stack is", st.size())
st.pop()
print("The size of the stack is", st.size())
st.push("Aloha")
st.pop()
st.pop()
st.pop()
print("The size of the stack is", st.size())