-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueue.py
51 lines (36 loc) · 836 Bytes
/
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
# implemeneting Queue class using collecions.deque
from collections import deque
class Queue:
def __init__(self):
self.queue = deque()
def enqueue(self, value):
return self.queue.appendleft(value)
def dequeue(self):
return self.queue.pop()
def is_empty(self):
return len(self.queue) == 0
def size(self):
return len(self.queue)
q = Queue()
q.enqueue(1)
q.enqueue(2)
q.enqueue(3)
q.enqueue(4)
print(q.queue)
q.dequeue()
print(q.queue)
print(q.size())
print(q.is_empty())
#using list as queue
stock_prices = []
stock_prices.insert(0, 101)
stock_prices.insert(0, 102)
stock_prices.insert(0, 103)
stock_prices.insert(0, 104)
print(stock_prices)
stock_prices.pop()
print(stock_prices)
stock_prices.pop()
print(stock_prices)
stock_prices.pop()
print(stock_prices)