Update stack.md and queue.md

This commit is contained in:
Yudong Jin 2023-01-05 01:59:31 +08:00
parent 3302354909
commit fd3eaaf3fd
2 changed files with 4 additions and 8 deletions

View File

@ -328,7 +328,7 @@ comments: true
queSize++;
}
/* 出队 */
int poll() {
void poll() {
int num = peek();
// 删除头结点
ListNode *tmp = front;
@ -336,7 +336,6 @@ comments: true
// 释放内存
delete tmp;
queSize--;
return num;
}
/* 访问队首元素 */
int peek() {
@ -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() {

View File

@ -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() {
@ -657,10 +656,9 @@ comments: true
stack.push_back(num);
}
/* 出栈 */
int pop() {
void pop() {
int oldTop = top();
stack.pop_back();
return oldTop;
}
/* 访问栈顶元素 */
int top() {