c - 我想做后缀功能,我要添加哪种情况?
问题描述
我想做后缀功能。但是如果我执行这个程序,它就会变成无限加载。我想我有足够的案例分类。所以,我不知道添加更多案例的条件,请让我知道我错过了什么
void toPostfix() {
/* infixExp pointer which read one bye on character */
char *exp = infixExp;
/* variable for storing char temporarily */
char x;
while (*exp != '\0') //iteration
{
if (getPriority(*exp) == operand) // if it is operated
{
charCat(exp); //put into postfixExp.
}
else
if (getPriority(*exp) == rparen) { /* In the case of')', the operator is subtracted from the postfixstack until'(' appears and put into postfixExp*/
while (getPriority(postfixStack[postfixStackTop]) != lparen) {
x = postfixPop(); // subtract operator from postfixstack
charCat(&x);//put in postfixExp
}
postfixPop(); //The'(' brackets are removed from postfixstack.
} else { /*If the operator you are trying to put in postfixstack has a lower priority than postfixStack[postfixStackTop]. After subtracting postfixStack[postfixStackTop], put it in postfixExp and enter postfixstack*/
while (getPriority(postfixStack[postfixStackTop]) >= getPriority(*exp)) {
x = postfixPop();// Subtract operator from postfixstack.
charCat(&x);// put it in postfixExp
}
postfixPush(*exp); // Put the operator in postfixstack.
}
exp++; //exp has the address value of infixExp, so increase the address value by 1 byte.
}
while (postfixStack[postfixStackTop] != '\0') {
x = postfixPop();
charCat(&x);
}
}
解决方案
前
while (getPriority(postfixStack[postfixStackTop]) >= getPriority(*exp))
一条线
if (postfixStack[postfixStackTop] != '(')
缺少,因为如果堆栈顶部有括号运算符,则不允许从while
循环中的后缀堆栈中弹出任何运算符,而与其优先级无关。
推荐阅读
- python - 如何在 Python 中获取类的参数名称?
- javascript - RN声音电平开关静音-160到0
- javascript - 如何在使用 Elementor 构建的可变产品页面上将起始价格范围替换为实际变化价格?
- go - 标题已经写好了。想要用 500 覆盖状态码 200
- qt - 在 Yocto 中应用 .patch 文件不起作用
- javascript - 如何从外部 ip 访问我的 Vue 应用程序?
- json - 条件渲染在 reactjs 中的作用不统一?
- sql-server - 慢速插入:从视图中选择
- kubernetes - 如何从 Google Cloud Composer 的 KubernetesPodOperator 中的私有 Docker 注册表中提取图像?
- python - matplotlib 补丁 - 提取包含信息