后缀表达式转换

来源:百度知道 编辑:UC知道 时间:2024/06/08 01:04:53
表达式“X=A+B×(C-D)/E ”的后缀表示形式为XABCD-×E/+= (运算符优先级相同时,遵循左结合的原则)。
怎么转化成的啊??请给出个详细步凑。
晕,不要复制别人的代码,毫无意义

postfix函数为后缀表达式转换

#include <iostream>
#include <cmath>
#define MAXI 100
#define MAX 30

using namespace std;

typedef struct
{
char op;
double v;
}titem;

typedef struct
{
int cnt;
titem I[MAXI];
}express;

express E[MAX],H[MAX];
int weight[255];

bool is_operator(char c)
{
return (c=='+' || c=='-' || c=='*' || c=='/' || c=='^' || c=='(' ||c==')');
}

void init()
{
int i=0;
char c;
freopen("equal.in","r",stdin);
freopen("equal.out","w",stdout);
while (!cin.eof())
{
while ((c=cin.get())==10 || c==13 ||c==' ');
if (cin.eof())
break;
i++;
if (is_operator(c))
{
E[1].I[i].op=c;
}
else
{
cin.putback(c);