Skip to content

Commit

Permalink
[Issue 49]fix bug of deleting and then insert to tail
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryderry committed Oct 11, 2018
1 parent be1244e commit 01ae89d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion python/05_array/myarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def insert(self, index: int, value: int) -> bool:

def insert_to_tail(self, value: int) -> bool:
if self._count == self._capacity: return False
self._data.append(value)
if self._count == len(self._data):
self._data.append(value)
else:
self._data[self._count] = value
self._count += 1
return True

Expand All @@ -57,4 +60,6 @@ def print_all(self):
a.insert_to_tail(i)

a.delete(2)
print(a)
a.insert_to_tail(7)
print(a)

0 comments on commit 01ae89d

Please sign in to comment.