forked from psounis/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.py
More file actions
31 lines (24 loc) · 669 Bytes
/
queue.py
File metadata and controls
31 lines (24 loc) · 669 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
class Queue:
def __init__(self):
self.array = []
def enqueue(self, elem):
self.array.append(elem)
def dequeue(self):
if not self.array:
return None
else:
return self.array.pop(0)
def __str__(self):
return ", ".join(self.array)
def __add__(self, other):
new_q = Queue()
new_q.array = self.array[:]
new_q.enqueue(other)
return new_q
def __iadd__(self, other):
self.enqueue(other)
return self
def __neg__(self):
return self.dequeue()
def __len__(self):
return len(self.array)