1class ArrayQueue:
2 def __init__(self):
3 self._data = []
4 self._size = 0
5 self._front = 0
6
7 def __len__(self):
8 return self._size()
9
10 def is_empty(self):
11 return self._size == 0
12
13 def enqueue(self, e):
14 self._data.append(e)
15 self._size = self._size + 1
16
17 def deque(self):
18 if self.is_empty():
19 raise Empty('queue is empty')
20 else:
21 value = self._data[self._front]
22 self._data[self._front] = None
23 self._front = self._front + 1
24 self._size = self._size - 1
25 return value
26
27 def first(self):
28 if self.is_empty():
29 raise Empty('queue is empty')
30 else:
31 return self._data[self._front]
32
33
34class Empty(Exception):
35 pass
36