表达式求值,说起来很复杂,我有源代码,你自己研究研究
#include
#include
#define MaxSize 99
void translate(char str[],char exp[]) /*将算术表达式转换成后缀表达式*/
{
struct
{
char data[MaxSize];
int top; /*top为栈顶*/
}op; /*定义一个含data和top的结构体*/
char ch;
int i = 0,t = 0;
op.top = -1;
ch = str[i]; /*将str的每一个数转换成ch*/
i++;
while(ch != '\0') /*ch对应不同的符号的时候对应的转换情况*/
{
switch(ch)
{
case '(': /*当是(的时候,将此括号存入栈op*/
op.top++;op.data[op.top]=ch;
break;
case ')':
while(op.data[op.top] != '(') /*括号内的转换优先级最高,故先提取表达式*/
{
exp[t]