用递归进行链表逆置

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

 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 }
原文地址:https://www.cnblogs.com/yang-wen/p/6657188.html