Skip to content

Commit

Permalink
Merge pull request wangzheng0822#47 from gitferry/master
Browse files Browse the repository at this point in the history
增加了入队时进行数据迁移的代码
  • Loading branch information
wangzheng0822 authored Oct 12, 2018
2 parents e6bf08b + 0d077d1 commit 871ff97
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions python/09_queue/array_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ def __init__(self, capacity: int):
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

Expand Down

0 comments on commit 871ff97

Please sign in to comment.