将线性表重置为空表的函数对么

来源:百度知道 编辑:UC知道 时间:2024/05/27 16:02:57
void ClearList(struct student *head)
{
struct student *p1;
p1=head;
p1=p1->next;
while(p1)
{
p1->num=NULL;
p1=p1->next;
}
}

这是链表,并不需要置每个表单元为空,只需head->next=NULL即可
void ClearList(struct student *head)
{
if(head->next)
head->next=NULL;
}

如果是把链表的每个表单元置空,那么你的答案可以做到,但是这种用法貌似没有用过,这样做就失去了链表的优势