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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_42304745/article/details/81220180

 

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;

}

 

展开阅读全文

没有更多推荐了,返回首页