关于#c++#的问题:表达式求值



```c++

/***链栈实现后缀表达式求值***/

#include
using namespace std;

const char oper[7] = { '+', '-', '*', '/', '(', ')', '#' };
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef char SElemType;
typedef int Status;
typedef struct SNode {
    int data;
    struct SNode *next;
} SNode, *LinkStack;

Status InitStack(LinkStack &S) {
    S = NULL;
    return OK;
}
bool StackEmpty(LinkStack S) {
    if (!S)
        return true;
    return false;
}
Status Push(LinkStack &S, SElemType e) {
    SNode *p = new SNode;
    if (!p) {
        return OVERFLOW;
    }
    p->data = e;
    p->next = S;
    S = p;
    return OK;
}
Status Pop(LinkStack &S, SElemType &e) {
    SNode *p;
    if (!S)
        return ERROR;
    e = S->data;
    p = S;
    S = S->next;
    delete p;
    return OK;
}
Status GetTop(LinkStack &S) {
    if (!S)
        return ERROR;

    return S->data;
}
bool In(char ch) {//判断ch是否为运算符
    for (int i = 0; i < 7; i++) {
        if (ch == oper[i]) {
            return true;
        }
    }
    return false;
}
char Precede(char theta1, char theta2) {//判断运算符优先级
    if ((theta1 == '(' && theta2 == ')') || (theta1 == '#' && theta2 == '#')) {
        return '=';
    } else if (theta1 == '(' || theta1 == '#' || theta2 == '(' || (theta1
            == '+' || theta1 == '-') && (theta2 == '*' || theta2 == '/')) {
        return '<';
    } else
        return '>';
}
char Operate(char first, char theta, char second) {//计算两数运算结果
    switch (theta) {
    case '+':
        return (first - '0') + (second - '0') + 48;
    case '-':
        return (first - '0') - (second - '0') + 48;
    case '*':
        return (first - '0') * (second - '0') + 48;
    case '/':
        return (first - '0') / (second - '0') + 48;
    }
    return 0;
}

//实验 后缀表达式求值
char EvaluateExpression() {//算术表达式求值的算符优先算法,设OPTR和OPND分别为运算符栈和操作数栈
    LinkStack OPND,OPTR;
    char ch, theta, a, b, x, top;
    InitStack(OPTR); //初始化OPTR栈
    Push(OPTR, '#'); //将表达式起始符“#”压入OPTR栈
    cin >> ch;
    while (ch != '#' || (GetTop(OPTR) != '#')) //表达式没有扫描完毕或OPTR的栈顶元素不为“#”
    {
        if(!In(ch)){Push(OPND,ch);cin>>ch;}
        else
            switch(Precede(GetTop(OPTR),ch)){
            case '<':
                Push(OPTR,ch);cin>>ch;
                break;
            case'>':
                Pop(OPTR,theta);
                Pop(OPND,b);Pop(OPND,a);
                Push(OPND,Operate(a,theta,b));
                break;
            case'=':
                Pop(OPTR,x);cin>>ch;
                break;
        }
    } //while
    return GetTop(OPND); //OPND栈顶元素即为表达式求值结果
}

int main(){
    char a=EvaluateExpression();
    cout<return 0;
}

```请问大神这有什么问题,没有输出

你碰到的具体问题是?

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^