You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to propose adding an implementation of Postfix (Reverse Polish Notation) Expression Evaluation in Java using a Stack.
The repository currently has InfixToPostfix.java and InfixToPrefix.java, which convert expressions into postfix/prefix notation, but there is no implementation that actually evaluates a postfix expression to compute its result. This would be a natural and useful complement to the existing conversion utilities.
Proposed Changes
I would like to add:
PostfixEvaluation.java under src/main/java/com/thealgorithms/stacks/
Complete implementation with clear Javadoc explanations (O(N) Time, O(N) Space).
Support for standard operators (+, -, *, /) and multi-digit operands.
Proper handling of invalid expressions / division by zero.
PostfixEvaluationTest.java under src/test/java/com/thealgorithms/stacks/
Comprehensive JUnit 5 test suite covering standard expressions, negative results, single-operand expressions, and invalid input handling.
Verification
I will ensure all code follows the project's formatting rules and passes ./gradlew test / mvn test locally before opening a PR.
I would love to implement this as my first open-source contribution! Could a maintainer please assign this issue to me?
Given a valid postfix expression (e.g., "23+" representing 2 + 3), evaluate it to a single numeric result using a stack.
Key Logic:
Scan the expression token by token.
If the token is an operand, push it onto the stack.
If the token is an operator, pop the top two operands, apply the operator, and push the result back onto the stack.
After processing all tokens, the stack contains exactly one value — the final result.
Complexity Analysis
Time Complexity: O(N) — single pass through the expression.
Space Complexity: O(N) — stack storage in the worst case (all operands).
Planned Files & Folder Structure
src/main/java/com/thealgorithms/stacks/PostfixEvaluation.java (Implementation)
src/test/java/com/thealgorithms/stacks/PostfixEvaluationTest.java (JUnit 5 Test Suite)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!
Please reopen this issue once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution!
Activity
9ifrashaikh commentedon Sep 1, 2026
@DenizAltunkapan @alxkm @yanglbme could one of you please assign this to me? I'd like to work on it as my first contribution
DenizAltunkapan commentedon Sep 1, 2026
@9ifrashaikh i think this already exists in https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/stacks/PostfixEvaluator.java , please always check for existing implementations first.
github-actions commentedon Oct 2, 2026
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!
github-actions commentedon Oct 9, 2026
Please reopen this issue once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution!