删除链表中的数据

//删除链表中数据位item的数据
//copyright @anduo 
//date:2012.10.10
void PurgeItem(LinkList &list)
{
	LinkList p, q =list;
	p = list->next;
	
	//judge the second node 
	while (p != NULL)
	{
		if (p->data == item)
		{
			q->next = p->next;
			free(p);
			p = q-next;
		}
		else
		{
			q = p;
			p = p->next;
		}
	}

	//judge if the first node is item 
	if (list->data == item)
	{
		q = list;
		list = list->next;
		free(q);
	}
}


你可能感兴趣的:(list,null)