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语言编写的
最佳答案
如果temp
为NULL
,则run = temp->pdown;
是无效操作。
}
temp = temp->pnext;
if (temp!=NULL) //add this line
run = temp->pdown;
关于c - 函数不返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22816146/