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