-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStacksArrays.py
More file actions
49 lines (37 loc) · 752 Bytes
/
StacksArrays.py
File metadata and controls
49 lines (37 loc) · 752 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
41
42
43
44
45
class StacksArray:
def __init__(self):
self._data = []
def __len__(self):
return len(self._data)
def isempty(self):
return len(self._data) == 0
def push(self, e):
self._data.append(e)
def pop(self):
if self.isempty():
print('Stack is empty')
return
return self._data.pop()
def top(self):
if self.isempty():
print('Stack is empty')
return
return self._data[-1]
S = StacksArray()
S.push(5)
S.push(3)
print(S._data)
print(len(S))
print(S.pop())
print(S.isempty())
print(S.pop())
print(S.isempty())
S.push(7)
S.push(9)
print(S.top())
S.push(4)
print(len(S))
print(S.pop())
S.push(6)
S.push(8)
print(S.pop())