Merge pull request #47 from gitferry/master

增加了入队时进行数据迁移的代码
This commit is contained in:
wangzheng0822 2018-10-12 17:49:50 +08:00 committed by GitHub
commit 871ff9746d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,9 +16,16 @@ class ArrayQueue:
self._tail = 0
def enqueue(self, item: str) -> bool:
if self._tail == self._capacity: return False
if self._tail == self._capacity:
if self._head == 0:
return False
else:
for i in range(0, self._tail - self._head):
self._data[i] = self._items[i + self._head]
self._tail = self._tail - self._head
self._head = 0
self._items.append(item)
self._items.insert(self._tail, item)
self._tail += 1
return True