-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStackListLimited.py
62 lines (51 loc) · 1.39 KB
/
StackListLimited.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Created by Elshad Karimov on 22/05/2020.
# Copyright © 2020 AppMillers. All rights reserved.
class Stack:
def __init__(self, maxSize):
self.maxSize = maxSize
self.list = []
def __str__(self):
values = self.list.reverse()
values = [str(x) for x in self.list]
return '\n'.join(values)
# isEmpty
def isEmpty(self):
if self.list == []:
return True
else:
return False
# isFull
def isFull(self):
if len(self.list) == self.maxSize:
return True
else:
return False
# Push
def push(self, value):
if self.isFull():
return "The stack is full"
else:
self.list.append(value)
return "The element has been successfully inserted"
# Pop
def pop(self):
if self.isEmpty():
return "There is not any element in the stack"
else:
return self.list.pop()
# peek
def peek(self):
if self.isEmpty():
return "There is not any element in the stack"
else:
return self.list[len(self.list)-1]
# delete
def delete(self):
self.list = None
customStack = Stack(4)
print(customStack.isEmpty())
print(customStack.isFull())
customStack.push(1)
customStack.push(2)
customStack.push(3)
print(customStack)