求值后缀表达式 3 5*6 7+11/ -
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/10/03 00:37:52
求值后缀表达式 3 5*6 7+11/ -
program hzbds_1010;
type stack=record
data:array[1..100] of real;
top:0..100;
end;
var s:stack;
ch:char;
i:integer;
x:real;
a:array[1..10] of char;
function pop(var s:stack):real; {enter}
begin
pop:=s.data[s.top];
s.top:=s.top-1;
end;
procedure push(var s:stack;x:real); {out}
begin
s.top:=s.top+1;
s.data[s.top]:=x;
end;
{main}
begin
i:=0;
repeat
i:=i+1;
read(a[i]);
until a[i]='@';
s.top:=0;
i:=1;
ch:=a[i];
while ch'@'do
begin
case ch of
'0'..'9':begin
x:=0;
while ch' 'do
begin
x:=x*10+ord(ch)-ord('0');
i:=i+1;
ch:=a[i];
end;
end;
'+':x:=pop(s)+pop(s);
'-':begin x:=pop(s);x:=pop(s)-x; end;
'*':x:=pop(s)*pop(s);
'/':begin x:=pop(s);x:=pop(s)/x; end;
end;
push(s,x);
i:=i+1;ch:=a[i];
end;
writeln(trunc(pop(s)));
end.
用pascal 运行一下注意结尾用@来结束输入
type stack=record
data:array[1..100] of real;
top:0..100;
end;
var s:stack;
ch:char;
i:integer;
x:real;
a:array[1..10] of char;
function pop(var s:stack):real; {enter}
begin
pop:=s.data[s.top];
s.top:=s.top-1;
end;
procedure push(var s:stack;x:real); {out}
begin
s.top:=s.top+1;
s.data[s.top]:=x;
end;
{main}
begin
i:=0;
repeat
i:=i+1;
read(a[i]);
until a[i]='@';
s.top:=0;
i:=1;
ch:=a[i];
while ch'@'do
begin
case ch of
'0'..'9':begin
x:=0;
while ch' 'do
begin
x:=x*10+ord(ch)-ord('0');
i:=i+1;
ch:=a[i];
end;
end;
'+':x:=pop(s)+pop(s);
'-':begin x:=pop(s);x:=pop(s)-x; end;
'*':x:=pop(s)*pop(s);
'/':begin x:=pop(s);x:=pop(s)/x; end;
end;
push(s,x);
i:=i+1;ch:=a[i];
end;
writeln(trunc(pop(s)));
end.
用pascal 运行一下注意结尾用@来结束输入
求值后缀表达式 3 5*6 7+11/ -
后缀表达式求值算法
后缀表达式求值 c++
将中缀表达式6-8/4+3×5-(7-3)×8/(5-2)转为后缀表达式
表达式求值中缀表达式转换为后缀表达式,并求值,(C语言)
与中缀表达式23+((12*3-2)/4+34*5/7)+108/9等价的后缀表达式为——?
1.表达式(1+34)*5-56/7的后缀表达式为( )
中缀表达式3 + 4/(25 -(6+15))* 8转换为后缀表达式
把此中缀表达式1 + (2-3) * 4 - 10 / 5 转为后缀表达式.要准确.
中缀表达式为:5*x-3+b/x^2 的前缀 后缀表达式分别是什么?
几个后缀中缀 表达式互转 的表达式: 1. 后缀转中缀 24 8 + 3 * 4 10 7 - * / @ 2. 中缀转
算术表达式能实现前缀后缀和中缀的表达是求值设计表达式的存储结构能求出结果