码迷,mamicode.com
首页 > 其他好文 > 详细

用递归进行链表逆置

时间:2017-04-01 18:58:12      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:node   log   方法   else   参数   logs   链表   color   逆置   

将不带头结点的链表进行逆置,一般可以采取用多个节点指针的方式。这里采用递归的方法。

 

 1 node* reverse(node* head , node* front = NULL)//head为头指针,调用此函数时只需传入第一个参数。返回值是逆置后链表的头指针
 2 {
 3     if(head == NULL)
 4     {
 5         return head ;
 6     }
 7     if(head->next != NULL)
 8     {
 9         node* temp = reverse(head->next , head) ;
10         head->next = front ;
11         return temp ;
12     }
13     else
14     {
15         head->next = front ;
16         return head ;
17     }
18 }

 

用递归进行链表逆置

标签:node   log   方法   else   参数   logs   链表   color   逆置   

原文地址:http://www.cnblogs.com/yang-wen/p/6657188.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!