-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_list_oop.py
More file actions
39 lines (31 loc) · 790 Bytes
/
stack_list_oop.py
File metadata and controls
39 lines (31 loc) · 790 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
class Stack:
def __init__(self):
self.data = []
def is_empty(self):
return len(self.data) == 0
def push(self, item):
self.data.append(item)
def pop(self):
if self.is_empty():
return "stack empty"
else:
return self.data.pop()
def display(self):
print(self.data)
def peek(self):
if self.is_empty():
return "stack empty"
else:
return self.data[-1]
stack1 = Stack()
stack1.push('a')
stack1.push('b')
stack1.display()
print("Top: " + stack1.peek())
print("Deleted: " + stack1.pop())
stack1.display()
print()
print("pop 2 more times")
print("----------------------------------------")
print(stack1.pop())
print(stack1.pop())