循环链表删除,逆置

循环链表按值删除,代码如下:
bool delete_val(List *list, ElemType key)
{
	Node *q = find(list,key);
	if(q == NULL)
		return false;

	if(q == list->last)
		list->last = q->prev;

	q->next->prev = q->prev;
	q->prev->next = q->next;
	free(q);
	list->size--;
	return true;
} 
逆置:<pre name="code" class="html">bool resver(List *list)
{
	Node *p = list->first->next;
	Node *q = p->next;
	p->next = list->first;
	list->first->prev = p;
	list->last = p;

	while(q!=list->first)
	{
		p = q;
		q = q->next;

		p->next = list->first->next;
		p->next->prev = p;
		p->prev = list->first;
		list->first->next = p;
	}
	return true;
}

 

你可能感兴趣的:(循环链表删除,逆置)