[FEATURE REQUEST] <title>Add Postfix Expression Evaluation implementation with JUnit tests
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 78/100
Direção de pesquisa
Comece lendo src/main/java/com/thealgorithms/stacks/InfixToPostfix.java e InfixToPrefix.java para seguir as convenções do pacote e do projeto. Adicione o arquivo nomeado PostfixEvaluation.java e seu correspondente para JUnit 5, cobrindo operadores padrão, operandos com vários dígitos, resultados negativos, operandos únicos, expressões inválidas e divisão por zero. Execute ./gradlew test ou mvn test; considera-se concluído quando os novos testes passam e as regras de formatação são atendidas.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- Java
- Estrelas
- 66.3k
- Forks
- 21.3k
- Merge médio
- 16h 57min
- PRs com merge (30d)
- 23
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de TheAlgorithms/Java
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 78/100
TheAlgorithms/Java#7599 ·
-
enhancement
TheAlgorithms/Java#7579 · 4 comentários · 2 responsáveis ·
-
hacktoberfest help wanted
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 1/100
TheAlgorithms/Java#7546 · 5 comentários ·
-
enhancement
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 20/100
TheAlgorithms/Java#6974 · 3 comentários ·
Todas as issues de TheAlgorithms/Java
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
bug needs triage
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 94/100
objectionary/hone-maven-plugin#1061 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
spring-projects/spring-modulith#1895 ·