TheAlgorithms / TheAlgorithms/Java
[FEATURE REQUEST] <title>Add Postfix Expression Evaluation implementation with JUnit tests
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 66.3k
- フォーク
- 21.3k
- 平均マージ
- 16時間 57分
- マージ済み PR(30日)
- 23
説明
What would you like to Propose?
Feature Description
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?
Issue details
Issue Details & Algorithm Overview
- Algorithm Description
Algorithm: Postfix (Reverse Polish Notation) Expression Evaluation
Category: Stacks / Expression Evaluation
Language: Java
- How the Algorithm Works
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)
Additional Information
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず src/main/java/com/thealgorithms/stacks/InfixToPostfix.java と InfixToPrefix.java を読んで、パッケージとプロジェクトの規約に合わせてください。指定された PostfixEvaluation.java と、それに対応する JUnit 5 のテストを追加し、標準演算子、複数桁のオペランド、負の結果、単一のオペランド、無効な式、ゼロ除算を対象にします。./gradlew test または mvn test を実行してください。新しいテストが成功し、フォーマット規則を満たせば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- backend
- issue の種類
- 機能追加
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 活発
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 78/100