shunting yard 알고리즘에 대한 메소드를 작성하기 전에 여기에서 메소드를 작성하여 후위 표현식을 평가할 수 있습니다. postfix 대기열에서 수행 할 수 있도록이 calculate 메서드를 호출합니다. 내가 "변환"변환 할 때 double을 String으로 변환하려고 할 때 해석 할 수없는 변수
while(!(token==null)) {
if(isOperator(token)) {
double operand_2 = Double.parseDouble(polish.pop());
double operand_1 = Double.parseDouble(polish.pop());
if(token.contains("+")) {
double result = operand_2 + operand_1;
}
else if(token.contains("-")) {
double convert = operand_2 - operand_1;
}
else if(token.contains("/")) {
double convert = operand_2/operand_1;
}
else if(token.contains("*")) {
double convert = operand_2/operand_1;
}
을 읽을 수있는 토큰이있는 동안
public String calculate(Queue post, Stack polish) {
난 내 큐 큐에서 개별 토큰으로 분리해서 것은
String token = post.Dequeue();
읽을 수 String으로 전환하면 convert가 변수로 변환 될 수 없음을 알립니다.
String result = Double.toString(convert);
polish.push(result);
}
else if(isNumeric(token)){
polish.push(token);
}
String finalVal = polish.pop();
return finalVal;
}
}
Plz은 투표 및 동의하는 것을 잊지 마세요 –