Skip to content

Commit ec5ae17

Browse files
committed
Stacks
1 parent 9ca6d1e commit ec5ae17

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Stacks /StacksArrays.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
class StacksArray:
2+
3+
def __init__(self):
4+
self._data = []
5+
6+
def __len__(self):
7+
return len(self._data)
8+
9+
def isempty(self):
10+
return len(self._data) == 0
11+
12+
def push(self, e):
13+
self._data.append(e)
14+
15+
def pop(self):
16+
if self.isempty():
17+
print('Stack is empty')
18+
return
19+
return self._data.pop()
20+
21+
def top(self):
22+
if self.isempty():
23+
print('Stack is empty')
24+
return
25+
return self._data[-1]
26+
27+
28+
S = StacksArray()
29+
S.push(5)
30+
S.push(3)
31+
print(S._data)
32+
print(len(S))
33+
print(S.pop())
34+
print(S.isempty())
35+
print(S.pop())
36+
print(S.isempty())
37+
S.push(7)
38+
S.push(9)
39+
print(S.top())
40+
S.push(4)
41+
print(len(S))
42+
print(S.pop())
43+
S.push(6)
44+
S.push(8)
45+
print(S.pop())
46+
47+
48+
49+

0 commit comments

Comments
 (0)