Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 中缀到中缀有公式吗?_Java_Computer Science - Fatal编程技术网

Java 中缀到中缀有公式吗?

Java 中缀到中缀有公式吗?,java,computer-science,Java,Computer Science,嗨,我能寻求一些帮助吗?有中缀到后缀的公式吗?…我不知道如何转换它们,如何给出后缀表达式和后缀求值。。。 例如,这个1*2(5+2)-9/6。按照以下步骤从infix转换为postfix: Define a stack Go through each character in the string If it is between 0 to 9, append it to output string. If it is left brace push to stack If it is oper

嗨,我能寻求一些帮助吗?有中缀到后缀的公式吗?…我不知道如何转换它们,如何给出后缀表达式和后缀求值。。。
例如,这个1*2(5+2)-9/6。

按照以下步骤从
infix
转换为
postfix

Define a stack
Go through each character in the string
If it is between 0 to 9, append it to output string.
If it is left brace push to stack
If it is operator *+-/ then 
    If the stack is empty push it to the stack
    If the stack is not empty then start a loop:
            If the top of the stack has higher precedence
            Then pop and append to output string
            Else break
        Push to the stack

If it is right brace then
    While stack not empty and top not equal to left brace
    Pop from stack and append to output string
    Finally pop out the left brace.

If there is any input in the stack pop and append to the output string.

如果您想获得不同符号的表达式,一种方法是使用二叉树并使用前/中/后顺序遍历进行转换。

您查看了我们的教科书吗?我记得早期的CS课程要求我们做一个类似的转换,我们的教科书中概述了算法。那么后缀评估呢?