Java中的调车场算法不工作?
这是我的密码:Java中的调车场算法不工作?,java,postfix-notation,shunting-yard,Java,Postfix Notation,Shunting Yard,这是我的密码: public String ShuntingYard(String input) { Tokenizer tokens = new Tokenizer(input); output = new LinkedList<String>(); stack = new MyStack<String>(new LinkedList<String>(), new LinkedList<String>());
public String ShuntingYard(String input) {
Tokenizer tokens = new Tokenizer(input);
output = new LinkedList<String>();
stack = new MyStack<String>(new LinkedList<String>(), new LinkedList<String>());
while (tokens.hasNextToken()){
String token = tokens.getNextToken();
if (isOperator(token)){
while (!stack.isEmpty() && isOperator(stack.peek())){
if ((leftassoc(token)&&precedence(token)<=precedence(stack.peek())) ||
(precedence(token)<precedence(stack.peek()))){
output.add(stack.pop());
}
else break; }
stack.push(token);
}
output.add(token);
}
while (!stack.isEmpty())
output.add(stack.pop());
return output.toString();
}
公共串调车场(串输入){
标记器标记=新标记器(输入);
输出=新的LinkedList();
stack=newmystack(newlinkedlist(),newlinkedlist());
while(tokens.hasNextToken()){
String token=tokens.getNextToken();
if(等运算符(令牌)){
而(!stack.isEmpty()&&isOperator(stack.peek()){
if((leftassoc(token)&&priority(token)基本上,您缺少一个“else”。请对照代码检查算法。在执行或未执行if(isOperator())
分支后,您没有正确处理该情况。您还没有实现“(“or”)。可能存在其他错误或遗漏。有关正确的实现,请参阅。