gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:45:00 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com