Fix my list.

This commit is contained in:
Yudong Jin
2022-12-25 12:58:35 +08:00
parent 8733557f00
commit 01b6c8bb0a
2 changed files with 8 additions and 2 deletions

View File

@ -55,11 +55,14 @@ class MyList:
""" 删除元素 """
def remove(self, index):
assert index < self.__size, "索引越界"
num = self.nums[index]
# 索引 i 之后的元素都向前移动一位
for j in range(index, self.__size - 1):
self.__nums[j] = self.__nums[j + 1]
# 更新元素数量
self.__size -= 1
# 返回被删除元素
return num
""" 列表扩容 """
def extend_capacity(self):