[FEATURE REQUEST] <title>Add Postfix Expression Evaluation implementation with JUnit tests
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 78/100
Rechercherichtung
Beginnen Sie mit dem Lesen von src/main/java/com/thealgorithms/stacks/InfixToPostfix.java und InfixToPrefix.java, um die Paket- und Projektkonventionen einzuhalten. Fügen Sie die benannte PostfixEvaluation.java und das zugehörige JUnit-5-Gegenstück hinzu, wobei Standardoperatoren, mehrstellige Operanden, negative Ergebnisse, einzelne Operanden, ungültige Ausdrücke und Division durch null abgedeckt werden. Führen Sie ./gradlew test oder mvn test aus; abgeschlossen ist die Aufgabe, wenn die neuen Tests bestehen und die Formatierungsregeln eingehalten werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Java
- Sterne
- 66.3k
- Forks
- 21.3k
- Ø Merge
- 16 Std. 57 Min.
- Gemergte PRs (30 T.)
- 23
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus TheAlgorithms/Java
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 78/100
TheAlgorithms/Java#7599 ·
-
enhancement
TheAlgorithms/Java#7579 · 4 Kommentare · 2 zugewiesene Personen ·
-
hacktoberfest help wanted
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 1/100
TheAlgorithms/Java#7546 · 5 Kommentare ·
-
enhancement
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 20/100
TheAlgorithms/Java#6974 · 3 Kommentare ·
Alle Issues in TheAlgorithms/Java
Ähnliche Issues
-
Bug Java Platform: Java
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
getsentry/sentry-java#6138 · 1 Kommentar ·
-
bug needs triage p2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
GoogleCloudPlatform/DataflowTemplates#4273 · 1 Kommentar ·
-
[Studio][Bug] Bulk-deleting a full page of alert rules steps the page back while more rules remain Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
apache/rocketmq-dashboard#4654 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100