struct ListNode { int val_; ListNode* next; ListNode(int val): val_(val),next(NULL){} }; //非递归 ListNode *reverse(ListNode *head) { if(head == NULL) return NULL; ListNode* vir = new ListNode(0); vir->next = NULL; ListNode *p = head; while(p != NULL)){ ListNode *q = p->next; p->next = vir->next; vir->next = p; p = q; } head = vir->next; delete vir; return head; } //递归 ListNode *reverse(ListNode *head) { if(head == NULL) return NULL; if(head->next == NULL) return head; ListNode *tp = head->next; ListNode *p = reverse(tp); tp->next = head; head->next = NULL; return p; }