forked from ikushum/Lets-do-DataStructure-and-Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
41 lines (34 loc) · 774 Bytes
/
stack.py
File metadata and controls
41 lines (34 loc) · 774 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
class Stack:
def __init__(self,size):
self.size = size
self.top = -1
self.array = [None] * self.size
def isEmpty(self):
if(self.top == -1):
return True
else:
return False
def top(self):
return self.array[self.top]
def push(self, data):
if not (self.top < self.size-1):
print('Stack is full')
return
self.top+=1
self.array[self.top] = data
print(str(data) + ' was inserted')
def pop(self):
if (self.top == -1):
print('Stack is empty')
return None
else:
print(str(self.array[self.top]) + ' was deleted')
obj = self.array[self.top]
self.array[self.top] = None
self.top-=1
return obj
def display(self):
if (self.top == -1):
print('Stack is empty')
else:
print('Stack is : ' + str(self.array) )