-
-
Notifications
You must be signed in to change notification settings - Fork 139
Update expr.c #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Update expr.c #91
Conversation
Filling the stack should start from element with index 0.
ohkimur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! The change from pre-increment/decrement to post-increment/decrement looks correct and fixes the off‑by‑one behavior:
- In
push,stack[stack_pointer++] = element;is the right choice ifstack_pointertracks the next free slot. - In
pop,return stack[--stack_pointer];correctly moves back to the last pushed element before reading.
A couple of suggestions to strengthen this and future contributions:
- Add brief comments documenting the stack invariant: “
stack_pointerpoints to the next free slot.” - Include small tests (or a demo
main) for: push/pop single item, push until full, pop until empty, and verify strict LIFO. - Consider returning a status from
push/pop(e.g., int/bool with out‑param) instead of printing errors; returning0frompopis ambiguous if0.0is a valid value. - Use
size_tforstack_pointerand comparisons withSTACK_SIZE. - Optionally guard against overflow/underflow with asserts in debug builds.
Overall, nice, focused fix with clear correctness improvement. If you’re up for it, similar sanity checks and invariants across other stack/queue exercises would be super valuable.
Thank you for the suggestions, I would be happy to contribute more (if my time allows)! |
|
@JebediahS Hello, are you still interested to contribute on this PR, or shall I close it? |
Sorry for the delay, still interested! |
ohkimur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JebediahS Hello, are you still interested to contribute on this PR, or shall I close it?
Sorry for the delay, still interested!
Great! Whenever you want to merge this PR, just make sure you checkout the new CONTRIBUTIONS.md file, as this a new addition to the repo so it makes the code more consistent and a bit more modern.
ohkimur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JebediahS Also, you'll need to merge the new changes from main first in your local branch to solve the merge conflicts.
To not mess up your style: In which form do you expect the tests to be set up? Should there be a test-folder |
Filling the stack should start from element with index 0.