-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.py
42 lines (34 loc) · 874 Bytes
/
stack.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 21 23:21:04 2023
@author: vishnujayan
"""
#set the size
class Stack:
def __init__(self, size):
self.top = -1
self.size = size
self.stack = [0 for i in range(size)]
def push(self, value):
if self.top >= self.size:
return "Stack overflow"
self.top +=1
self.stack[self.top] = value
return "Succesfully pushed the value"
def pop(self):
if self.top == -1:
return "Nothing to delete"
self.stack[self.top] = 0
self.top -= 1
return f"Successfully poped the last element"
stack = Stack(5)
for i in range(1,6):
print(stack.push(i))
print(stack.stack)
print(stack.pop())
print(stack.stack)
print(stack.pop())
print(stack.pop())
print(stack.pop())
print(stack.stack)