【发布时间】:2019-07-29 14:36:02
【问题描述】:
我已将我的函数代码粘贴到以下结构的内容中:
struct LetterFrequencyPair
{
char character;
int frequency;
struct LetterFrequencyPair* next;
};
创建和显示列表不是问题并且可以正常工作。但是,当我释放功能时,什么也没有发生。为了找出问题的原因,我在代码中添加了打印的步骤语句。 (见下面的函数)查看执行了多少代码。在输出中,我得到的只是“第 1 步”,没有其他内容,这表明错误在该行之后。我不确定这里有什么不正确的,因为它与我在另一个链表练习中使用的格式相同。
如果您发现我哪里出错了,请告诉我。另外,如果您需要查看整个代码(我很确定您不应该,因为这是错误所在),请告诉我,我将编辑问题以将其添加。:)
void freeList()
{
struct LetterFrequencyPair* temp;
temp = root;
if (temp == NULL)
{
printf("List is empty.\n");
}
else
{
printf("step 1\n");
while(temp != NULL);
{
printf("Step 2.\n");
struct LetterFrequencyPair* nexttemp = temp->next;
printf("step 3\n");
free(temp);
printf("Step 4\n");
temp = nexttemp;
printf("5\n");
}
printf("\n");
}
}
【问题讨论】:
-
while(temp != NULL);注意;
标签: c linked-list nodes free