Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 我想做后缀函数,我需要添加哪种情况?_C_Algorithm - Fatal编程技术网

C 我想做后缀函数,我需要添加哪种情况?

C 我想做后缀函数,我需要添加哪种情况?,c,algorithm,C,Algorithm,我想做后缀函数。但是如果我执行这个程序,它将变成无限负载。我想我有足够的病例分类。所以,我不知道哪些条件可以添加更多的案例,请让我知道我错过了什么 void toPostfix() { /* infixExp pointer which read one bye on character */ char *exp = infixExp; /* variable for storing char temporarily */ char x; w

我想做后缀函数。但是如果我执行这个程序,它将变成无限负载。我想我有足够的病例分类。所以,我不知道哪些条件可以添加更多的案例,请让我知道我错过了什么

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);
    }
}
以前

一行

          if (postfixStack[postfixStackTop] != '(')

缺少,因为如果堆栈顶部有一个括号运算符,则不允许在
while
循环中从postfixstack弹出任何运算符,这与其优先级无关。

编辑问题以提供一个,包括可编译和执行的完整程序、再现问题的示例输入、预期输出、,和观察到的输出或行为。请尝试。。。你读了吗?在编辑你的代码时,我看到你有一个悬而未决的问题。编写嵌套if语句时,始终正确缩进,并且从不遗漏任何大括号!
          if (postfixStack[postfixStackTop] != '(')