迭代

代码
- /**
-  * Definition for singly-linked list.
-  * struct ListNode {
-  *     int val;
-  *     struct ListNode *next;
-  * };
-  */
- struct ListNode* reverseList(struct ListNode* head){
-     if(head == NULL || head->next == NULL) return head;
-     struct ListNode * p = reverseList(head->next);
-     head->next->next = head;
-     head->next = NULL;    
-     return p;
- }
回归
- 对于下一个或者自身为NULL的节点执行返回,此返回值为逆转后的头部
- 对于中间节点:使自己的下一个节点指向自己;使自己指向的节点为空;返回头部值;
代码
-     if(head == NULL || head->next == NULL) return head;
-     struct ListNode * p = reverseList(head->next);
-     head->next->next = head;
-     head->next = NULL;    
-     return p;