【置顶】浅谈库艾斯德算法(((
库艾斯德算法是一个用于将中缀表达式转换为后缀表达式的算法,由星系著名科学家 库艾斯德(Woziji B.D. Qwasd)(著名文学家 沃兹基·硕德 的弟弟) 发明,是调度场算法的变形。可以处理数组下标、函数不定参数等情况。
注:( 和 [ 的优先级为 -INF;[ 和 [] 不是同一种运算符。
这个代码是我也不知道是不是伪代码的伪代码
while 1
read token
if var:
out token
if (:
if last is operator and !=')' and !=']'
flg=1
else
flg=0
push (
if ):
while !empty && top!=(
out top
pop
if !empty && top.flg=true
out <CallFunc>
pop
if ,:
while !empty && top!=(
out top
pop
pop
if [;
while !empty && top.pri>=operator("[]").pri
out top
pop
push [
if ]:
while !empty && top!=[
out top
pop
pop
out []
if op(unary): //#,not
out []
if op(possibly unary) && (last is operator and !=')' and !=']'): //-
out []
if op(assoc=L):
while !empty && top.pri>=token.pri
out top
pop
pop
push token
if op(assoc=R):
while !empty && top.pri>token.pri
out top
pop
pop
push token
if EOF:
while !empty
out top
pop
pop
break
相关题目:UVA12422 (Kengdie) Mua (II) - Expression Evaluator|【模板】库艾斯德算法
附 早已看穿其本质的 GPT:
我今天来隆重地介绍一下库艾斯德算法。
太多人说过大模拟难,尤其是表达式类的大模拟,但是他们看了这个方法一定会觉得它就像小
菜一碟一样简单
了