-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5. Queue.py
64 lines (48 loc) · 1.27 KB
/
5. Queue.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from collections import deque
class Queue:
def __init__(self):
self.buffer = deque()
def enqueue(self,value):
self.buffer.appendleft(value)
def dequeue(self):
return self.buffer.pop()
def front_element(self):
return self.buffer[-1]
def last_element(self):
return self.buffer[0]
def is_empty(self):
return len(self.buffer) == 0
def size(self):
return len(self.buffer)
def __repr__(self):
return '{}'.format(self.buffer)
if __name__ == '__main__':
queue = Queue()
queue.enqueue({
'company':'Walmart',
'timestamp': '15 apr, 11.01am',
'price': 131.10
})
print(queue.dequeue())
print(queue)
print(queue.is_empty())
queue.enqueue({
'company':'Walmart',
'timestamp': '15 apr, 11.01am',
'price': 131.10
})
queue.enqueue({
'company':'Walmart',
'timestamp': '15 apr, 11.02am',
'price': 131.12
})
queue.enqueue({
'company':'Walmart',
'timestamp':'15 apr, 11.03am',
'price': 135
})
print(queue.front_element())
print(queue.last_element())
print(queue.dequeue())
print(queue.size())
print(queue)