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