-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmake_queue.py
52 lines (43 loc) · 980 Bytes
/
make_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
"""
Queue class
"""
class Queue:
"""
A simple implementation of a FIFO queue.
"""
def __init__(self):
"""
Initialize the queue.
"""
self._items = []
def __len__(self):
"""
Return the number of items in the queue.
"""
return len(self._items)
def __iter__(self):
"""
Create an iterator for the queue.
"""
for item in self._items:
yield item
def __str__(self):
"""
Return a string representation of the queue.
"""
return str(self._items)
def enqueue(self, item):
"""
Add item to the queue.
"""
self._items.append(item)
def dequeue(self):
"""
Remove and return the least recently inserted item.
"""
return self._items.pop(0)
def clear(self):
"""
Remove all items from the queue.
"""
self._items = []