c - 函数不返回

标签 c linked-list

struct m_queue{
       int ndata;
       struct m_queue* pnext;
       struct m_queue* pdown;
       };

 int search(struct m_queue* list,int key){  //returns the index where it founded the key, return -1 if key is not found
        struct m_queue* temp;//searches horizontal
        struct m_queue* run;//searches downward
        int i;
        temp = list;

        run = temp->pdown;

        getch();
        while(temp!=NULL){

            getch();
            while(run!=NULL){
                if(run->ndata == key)
                    return temp->ndata;
                else
                    run = run->pdown;
            }
            temp = temp->pnext;
            run = temp->pdown;

        }
        printf("returning -1");
        getch();
        return -1;

    }

我已经检查了其他函数,我很确定没有缺陷,但每当我调试程序时,它总是突出显示“run = temp->pdown”段。这个函数不返回-1,它只是在找到 key 时返回。这是用c语言编写的

最佳答案

如果tempNULL,则run = temp->pdown;是无效操作。

}
temp = temp->pnext;
if (temp!=NULL)  //add this line
    run = temp->pdown;

关于c - 函数不返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22816146/

相关文章:

algorithm - 多级遍历的数据结构

C++通过指针更新派生类对象中的变量

c - 列表不退出循环?

c - c 中整数的输入验证

c - 使用 atof() 将一组字符转换为 float

c - linux c-pthreads : problem with local variables

C++链表在删除具有重复值的节点时会出现段错误

c - 为什么在我的代码运行后进程被终止?处理返回 255

C-Fortran 混合编程

c - 变量被视为未初始化