Add python code of chapter queue to docs.
This commit is contained in:
@@ -72,15 +72,18 @@ public:
|
||||
}
|
||||
|
||||
/* 删除元素 */
|
||||
void remove(int index) {
|
||||
int remove(int index) {
|
||||
if (index >= size())
|
||||
throw out_of_range("索引越界");
|
||||
int num = nums[index];
|
||||
// 索引 i 之后的元素都向前移动一位
|
||||
for (int j = index; j < size() - 1; j++) {
|
||||
nums[j] = nums[j + 1];
|
||||
}
|
||||
// 更新元素数量
|
||||
numsSize--;
|
||||
// 返回被删除元素
|
||||
return num;
|
||||
}
|
||||
|
||||
/* 列表扩容 */
|
||||
|
@@ -51,11 +51,8 @@ public:
|
||||
|
||||
/* 出队 */
|
||||
int poll() {
|
||||
// 删除头结点
|
||||
if (empty())
|
||||
throw out_of_range("队列为空");
|
||||
int num = nums[front];
|
||||
// 队头指针向后移动,越过尾部后返回到数组头部
|
||||
int num = peek();
|
||||
// 队头指针向后移动一位,若越过尾部则返回到数组头部
|
||||
front = (front + 1) % capacity();
|
||||
return num;
|
||||
}
|
||||
|
Reference in New Issue
Block a user