algorithm - 如何使用堆栈评估反向抛光符号

标签 algorithm stack postfix-notation rpn

这个后缀表达式可以求值吗?

6 2 3 + - 3 8 2 / + * 2 5 3 +

最佳答案

是的,它可以。

S = new empty stack
while not eof
    t = read token
    if t is a binary operator
        y = pop(S)
        x = pop(S)
        push(S, t(x, y))
    else
        push(S, t)
print the contents of the stack S

关于algorithm - 如何使用堆栈评估反向抛光符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40328938/

相关文章:

java - C 中的堆栈使用与 Java 中的堆栈使用

c# - 后缀计算器

c - C 中的段错误 : Infix to Postfix Evaluation

algorithm - 迷宫中的最短路径

sql - 将任意 SQL SELECT TOP(x) 转换为 SELECT COUNT(*)?

c++ - 不确定在尝试扩展我的堆栈功能时是否使用继承

c++ - 堆栈和堆溢出利用意味着什么

parsing - 在调车场处理额外的运算符(operator)

algorithm - 更好的随机 "feeling"短序列整数生成器

Javascript 单行调试