-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack.py
More file actions
44 lines (36 loc) · 879 Bytes
/
stack.py
File metadata and controls
44 lines (36 loc) · 879 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
class Stack():
'''
stack data structure in python
'''
def __init__(self):
'''
create elements array
'''
self.elements=[]
def Push(self, item):
'''
add an item to the elements
'''
self.elements.append(item)
def Pop(self):
'''
get the last item of the elements
'''
return self.elements.pop(len(self.elements)-1)
def main():
'''
test the stack class
'''
import random
s = Stack()
test_items=[]
for i in range(random.randint(10, 100)):
test_items.append(random.randint(10, 100))
s.Push(test_items[i])
for i in range(len(test_items)-1, -1, -1):
if test_items[i] != s.Pop():
print("Wront answer !!!")
return
print("ok")
if __name__ == "__main__":
main()