关于逆波兰法

来源:百度知道 编辑:UC知道 时间:2024/05/15 18:26:21
我想用C编一个带有括号的 计算器
请教关于逆波兰法计算的方法
比如3-4*5-(2-3*5)*(2-5)
按逆波兰法是怎么一步一步计算下去的

双数组逆波兰表达式法:计算器
见源程(c语言):
#include "stdio.h"
#define m0 100
void main(){
char str[m0];
char exp[m0];
char stack[m0];
float stack1[m0],d;
char ch,c;
int i,j,t,top=0;
i=0;
clrscr();
do
{
i++;
scanf("%c",&str[i]);
}while (str[i]!='#'&&i!=m0);
t=1;
i=1;
ch=str[i];
i++;
while(ch!='#')
{
if(ch>='0'&&ch<='9')
{
exp[t]=ch;
t++;
}
else
if(ch=='(')
{
top++;
stack[top]=ch;
}
else
if(ch==')')
{
while(stack[top]!='(')
{
exp[t]=stack[top];
top--;
t++;
}
top--;
}
else
if (ch=='+'||ch=='-')
{
while(top!=0&&stack[top]!='(')
{
exp[t]=stack[top];
top--;
t++;
}
top++;
stack[top]=ch;
}
else
if(ch=='*'|