1.补充函数,功能是删除链表中所有值为x的结点
结构体:
typedef int datatype;
typedef struct link_node{
datatype info;
struct link_node *next;
}node;
typedef node *linklist;
待补充函数:
linklist delallx(linklist head,int x)
{
}
解法:
linklist delallx(linklist head,int x)
{
linklist *cur, *tmp;
while(head != NULL && head->info == x)//去掉起始部分等于x的结点
{
tmp = head;
head = head->next;
free(tmp);
}
if (head == NULL)
return;
cur = head;
while(cur->next != NULL) //去掉等于x的结点
{
if (cur->next->data == x)
{
tmp = cur->next;
cur->next = cur->next->next;
free(tmp);
continue;
}
cur = cur->next;
}
return head;
}