数据结构与算法分析 习题3.3

 

void swap1(Node*p, Node*List) {//单链表
	Node*beforeP;
	Node*afterP;
	beforeP->next = p;
	p->next = afterP;

	p->next = afterP->next;
	beforeP->next = afterP;
	afterP->next = p;
}

void swap2(Node*p, Node*List) {//双链表
	Node*beforeP;
	Node*afterP;
	beforeP = p->prev;
	afterP = p->next;

	p->next = afterP->next;
	beforeP->next = afterP;
	afterP->next = p;
	p->next->prev = p;
	p->prev = afterP;
	afterP->prev = beforeP;

}

 

你可能感兴趣的:(数据结构与算法分析)