Olá, estou tentando criar um método para transformar números infix em postfix (notação polonesa inversa) usando Stack, porém estou recebendo o seguinte erro: "The operator += is undefined for the argument types(s) String, void"
Estou recebendo esse erro nesse argumento:
postfix += opStack.pop();
Alguma idéia de como solucionar esse problema?
public String infixToPostfix2 (String infix) {
scanned = infix.split(" ");
String postfix = "";
Stack<String> opStack = new Stack<>();
for (int i = 0; i < scanned.length; i++) {
if (!operators.contains(scanned[i])) {
postfix += scanned[i];
}
else if (scanned[i] == "(") {
opStack.push(scanned[i]);
}
else if (scanned[i] == ")"){
while (opStack != null && opStack.getTop() != "(")
postfix += opStack.pop();
if (opStack != null && opStack.getTop() != "(")
return "Invalid Expression"; // invalid expression
else
opStack.pop();
}
else if (operators.contains(scanned[i])){
while (opStack != null && precedence(scanned[i]) <= precedence(opStack.getTop()))
postfix += opStack.pop();
opStack.push(scanned[i]);
}
}
while (opStack != null)
postfix = opStack.pop();
return postfix;
}