Skip to content

Commit 0112928

Browse files
JebediahSwenkp
authored andcommitted
Update expr.c
Filling the stack should start from element with index 0.
1 parent bdcee72 commit 0112928

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

chapter_5/exercise_5_10/expr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int main(int argc, char *argv[]) {
9595

9696
float pop(void) {
9797
if (stack_pointer > 0) {
98-
return stack[stack_pointer--];
98+
return stack[--stack_pointer];
9999
}
100100

101101
printf("Error: the stack is empty.\n");
@@ -104,7 +104,7 @@ float pop(void) {
104104

105105
void push(float element) {
106106
if (stack_pointer < STACK_SIZE) {
107-
stack[++stack_pointer] = element;
107+
stack[stack_pointer++] = element;
108108
} else {
109109
printf("Error: the stack is full.\n");
110110
}

0 commit comments

Comments
 (0)