Skip to content

Commit

Permalink
Update stack.md and queue.md
Browse files Browse the repository at this point in the history
  • Loading branch information
krahets committed Jan 4, 2023
1 parent 3302354 commit fd3eaaf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions docs/chapter_stack_and_queue/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,14 @@ comments: true
queSize++;
}
/* 出队 */
int poll() {
void poll() {
int num = peek();
// 删除头结点
ListNode *tmp = front;
front = front->next;
// 释放内存
delete tmp;
queSize--;
return num;
}
/* 访问队首元素 */
int peek() {
Expand Down Expand Up @@ -719,11 +718,10 @@ comments: true
rear = (rear + 1) % capacity();
}
/* 出队 */
int poll() {
void poll() {
int num = peek();
// 队头指针向后移动一位,若越过尾部则返回到数组头部
front = (front + 1) % capacity();
return num;
}
/* 访问队首元素 */
int peek() {
Expand Down
6 changes: 2 additions & 4 deletions docs/chapter_stack_and_queue/stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,13 @@ comments: true
stkSize++;
}
/* 出栈 */
int pop() {
void pop() {
int num = top();
ListNode *tmp = stackTop;
stackTop = stackTop->next;
// 释放内存
delete tmp;
stkSize--;
return num;
}
/* 访问栈顶元素 */
int top() {
Expand Down Expand Up @@ -657,10 +656,9 @@ comments: true
stack.push_back(num);
}
/* 出栈 */
int pop() {
void pop() {
int oldTop = top();
stack.pop_back();
return oldTop;
}
/* 访问栈顶元素 */
int top() {
Expand Down

0 comments on commit fd3eaaf

Please sign in to comment.