执行deleteNode(headNode, local)后,nextNode结点指向的地址值被改变了;其中deleteNode功能是删除headNode中的local信息
struct Node* deleteFileSameInfo(struct Node* headNode)
{
struct Node* nextNode = headNode->next;
if (nextNode == NULL)
{
return;
}
int i;
struct Node* frontNode = headNode;
while (frontNode != NULL)
{
char* local = frontNode->data.num;
nextNode = frontNode->next;
while (nextNode != NULL)
{
for (i = 0; i < strlen(local); i++)
{
if (local[i] != nextNode->data.num[i])
{
break;
}
}
if (i == strlen(local))
{
printf("发现相同工号(%s),", local);
deleteNode(headNode, local);
}
i = 0;
nextNode = nextNode->next;
}
frontNode = frontNode->next;
}
return headNode;
}
for (i = 0; i < strlen(local); i++)
{
if (local[i] != nextNode->data.num[i])
{
break;
}
}
if (i == strlen(local))
{
printf("发现相同工号(%s),", local);
deleteNode(headNode, local);
}
可以改为:
if(strcmp(local,nextNode->data.num) == 0)
{
printf("发现相同工号(%s),", local);
deleteNode(headNode, local);
}
中间夹了个deleteNode调用,这个函数是否引起错误,能否保障节点删除后链表的完整性以及当前循环的完整性