-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.py
More file actions
32 lines (26 loc) · 730 Bytes
/
queue.py
File metadata and controls
32 lines (26 loc) · 730 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
class Queue(object):
'''Queue'''
def __init__(self):
self.__list = []
def enqueue(self, item):
'''Add an item to the end of the queue'''
self.__list.append(item)
def dequeue(self):
'''Remove the item from the top of the queue '''
return self.__list.pop(0)
def is_empty(self):
'''Determine if the queue is empty'''
return self.__list == []
def size(self):
'''Return the number of items in the queue'''
return len(self.__list)
if __name__ == '__main__':
q = Queue()
q.enqueue(1)
q.enqueue(2)
q.enqueue(3)
q.enqueue(4)
print(q.dequeue())
print(q.dequeue())
print(q.dequeue())
print(q.dequeue())