TheAlgorithms / TheAlgorithms/Java
[FEATURE REQUEST] <title>Add Postfix Expression Evaluation implementation with JUnit tests
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Java
- Estrellas
- 66.3k
- Forks
- 21.3k
- Merge medio
- 16 h 57 min
- PR fusionados (30 d)
- 23
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza leyendo src/main/java/com/thealgorithms/stacks/InfixToPostfix.java e InfixToPrefix.java para ajustarte a las convenciones del paquete y del proyecto. Añade el archivo nombrado PostfixEvaluation.java y su complemento correspondiente para JUnit 5, cubriendo operadores estándar, operandos de varios dígitos, resultados negativos, operandos individuales, expresiones no válidas y división por cero. Ejecuta ./gradlew test o mvn test; se considera terminado cuando las nuevas pruebas pasan y se cumplen las reglas de formato.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- java
- Área
- backend
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Activo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 78/100