我已经通过gdb在代码中发现了这条代码以进行seg错误。然而,我似乎无法明白为什么?在发生seg故障之前,它将运行6/7次。 Temp是包含频率(int)的链接列表中的一个节点,我使用它来在升序链接列表中查找位置以插入新节点。为什么在构建二叉树时进行这种分割?
while (ind == 0 && temp != NULL)
{
temp = temp -> next;
if (temp -> frequency > parent_node -> frequency) /*<--- SEG FAULT HERE */
{
parent_node -> next = temp -> next; /* parent points at higher freq node */
temp -> next = parent_node; /* parent node is temp next */
ind = 1;
}
if (temp -> next == NULL)
{
temp -> next = parent_node;
ind = 1;
}
}
'温度=温度 - >下; ':'temp'变成'NULL' – BLUEPIXY
http://ericlippert.com/2014/03/05/how-to-debug-small-programs/ – slim
这并不完全清楚你的代码试图做什么(尽管我们知道这是不对的)。什么是'temp'和'parent_node'指向循环的入口,你希望他们在退出循环时指向什么?两行'parent_node-> next = temp-> next;'和'temp-> next = parent_node;'似乎在创建一个包含两个节点的循环列表。那是你要的吗? –