A bug fix.

This commit is contained in:
krahets
2023-12-19 21:55:57 +08:00
parent d9686e57dd
commit 9a5ab776d6
9 changed files with 30 additions and 34 deletions

View File

@ -42,7 +42,7 @@ bool isEmpty(ArrayStack *stack) {
/* 入栈 */
void push(ArrayStack *stack, int num) {
if (stack->size == MAX_SIZE) {
printf("stack is full.\n");
printf("栈已满\n");
return;
}
stack->data[stack->size] = num;
@ -52,7 +52,7 @@ void push(ArrayStack *stack, int num) {
/* 访问栈顶元素 */
int peek(ArrayStack *stack) {
if (stack->size == 0) {
printf("stack is empty.\n");
printf("栈为空\n");
return INT_MAX;
}
return stack->data[stack->size - 1];
@ -60,10 +60,6 @@ int peek(ArrayStack *stack) {
/* 出栈 */
int pop(ArrayStack *stack) {
if (stack->size == 0) {
printf("stack is empty.\n");
return INT_MAX;
}
int val = peek(stack);
stack->size--;
return val;