删除链表

cap77 cap77 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
建的链表有头结点,我把整条链表删除后按如下打印怎么会报错啊?

void Delete(Node *head)
{
Node *temp=head;
Node *pNext=NULL;
if (temp==NULL)
{
cout<<"No head!"<<endl;
return;
}
while (temp!=NULL)
{
pNext=temp;
temp=temp->next;
delete pNext;
pNext=NULL;
}
}

void Print(Node* head)
{
if(head==NULL)
{
cout<<"No Head!"<<endl;
return;
}
Node *temp=head->next;
if (temp==NULL)
{
cout<<"空表"<<endl;
return;
}
while (temp!=NULL)
{
cout<<temp->number<<" ";
temp=temp->next;
}
cout<<endl;
}
...全文
评论 9
收藏 已收藏
分享
返回顶部
cap77
C++ 语言 65,214 成员 250,514 内容