【发布时间】:2016-11-18 22:51:56
【问题描述】:
我正在为一个班级做这个小项目,我遇到了这个问题。 我在这个例子上运行了 ddd,当它退出 while 循环时 prev 设置为 null,导致分段错误。
当我运行 ddd 时,我注意到 temp 不为 null,并且两个“prev is nulln”打印语句不会被触发,但循环外的那个会触发。
你知道会发生什么吗?
while(temp)
{
printf("while loop.\n");
if(pe->y > temp->y)
{
printf("while - if reached.\n");
break;
}//end if statement
prev = temp;
if(prev == NULL)
printf("prev is null1\n");
temp = temp->next;
if(prev == NULL)
printf("prev is null2\n");
}//end while loop
if(prev == NULL)
printf("prev is null3\n");
prev->next = pe;//redit links so that node is added in.
pe->next = temp;
【问题讨论】:
-
只发布函数的一部分对于诊断问题没有用处。请发帖minimal reproducible example。
标签: c sorting graph linked-list