-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractical8.py
More file actions
52 lines (41 loc) · 1.28 KB
/
Copy pathpractical8.py
File metadata and controls
52 lines (41 loc) · 1.28 KB
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
46
47
48
49
50
51
52
# Name : PRATHAM MODI
# ID : 20CE056
# Aim : Write a Program in Python to implement a Stack Data Structure using Class and Objects, with push, pop and traversal method.
# GITHUB LINK : https://github.com/prathammodi333/python-programs
class Stack:
__dataList = []
def push(self, data):
self.__dataList.append(data)
def pop(self):
if len(self.__dataList) > 0:
return self.__dataList.pop()
else:
return "No elements left for popping operation!"
def get_stackSize(self):
return len(self.__dataList)
def printStack(self):
print(self.__dataList)
def has_next(self):
return bool(len(self.__dataList))
def next(self):
return self.pop()
def peek(self):
if len(self.__dataList) > 0:
return self.__dataList[-1]
else:
return "No Elements are there in stack."
def printPeek(self):
print(self.peek())
def printPop(self):
print(self.pop())
if __name__ == "__main__":
stack = Stack()
stack.printStack()
stack.push(10)
stack.printStack()
stack.push(20)
stack.push(30)
print(stack.peek())
stack.push(40)
stack.push(50)
stack.printStack()