单链表的逆置使用递归算法出现

更新时间:02-02 教程 由 灭队 分享

单链表的逆置使用递归算法出现?

node* reverse(node *head){if(head == NULL || head->next == NULL){return head;}node *cur = head;node *pre = NULL;node *tmp;while(cur->next){tmp = pre;pre = cur;cur = cur->next;pre->next = tmp; //操作pre的next逆转}cur->next = pre; //结束时,操作cur的next逆转return cur;}

声明:关于《单链表的逆置使用递归算法出现》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2187137.html