指针指向改变的位置出错

问题遇到的现象和发生背景

结构体链表删除重复数据

用代码块功能插入代码,请勿粘贴截图
void removeDuplicate(struct Node* headNode)
{
printList(headNode);
    struct Node* p = headNode->next;
    struct Node* q ;
    struct Node* leftq = p;
    int count = 0;
    while (p != NULL)
    {
        q = p->next;
        while (q != NULL)
        {
            if (!strcmp(p->data.ISBN, q->data.ISBN))
            {
                leftq->next = q->next;
                free(q);
                q = leftq->next;
                count++;
            }
            else
            {
                leftq = q;
                q = q->next;
            }
        }
        p = p->next;
        leftq = p;    
    }
}

运行结果及报错内容

img

img

我想要达到的结果

什么原因