forked from sirfaheem/ComputerScienceALevels
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass Stack (2).py
More file actions
33 lines (29 loc) · 774 Bytes
/
Class Stack (2).py
File metadata and controls
33 lines (29 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
class Stack():
def __init__(self,size):
self.__array = [''] * size
self.__tos = -1 #initialize tos to null
self.__size = size
def push(self,value):
if self.__tos < self.__size-1:
self.__tos +=1
self.__array[self.__tos] = value
else:
print("stack is full")
def pop(self):
t=''
if self.__tos == -1:
t = "stack is empty"
else:
t = self.__array[self.__tos]
self.__tos -=1
return t
myStack = Stack(3)
print(myStack.pop())
myStack.push('E')
myStack.push('C')
myStack.push('A')
myStack.push('Z')
print(myStack.pop())
print(myStack.pop())
print(myStack.pop())
print(myStack.pop())