-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
32 lines (26 loc) · 783 Bytes
/
stack.py
File metadata and controls
32 lines (26 loc) · 783 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
class Stack:
def __init__(self):
self.items=[]
def is_empty(self):
if len(self.items)==0:
print("Stack is empty")
else:
print("Stack is not empty")
def push(self,item):
self.items.append(item)
def pop(self,item):
if not self.is_empty():
return self.items.pop()
else:
raise IndexError("Stack is empty")
def peek(self):
if len(self.items)==0:
print("Stack is empty")
else:
return self.items[-1]
def define_size(self):
return f"Size of stack is: {len(self.items)}"
def print_stack(self):
if not self.is_empty():
for i in self.items:
print(self.items[i])