Description:
Reverse a singly linked list.
Code:
1 ListNode* reverseList(ListNode* head) { 2 ListNode* preNode = NULL; 3 ListNode* p = head; 4 ListNode* nextNode = NULL; 5 while (p) 6 { 7 nextNode = p->next; 8 p->next = preNode; 9 preNode = p; 10 p = nextNode; 11 } 12 return preNode;//这里要注意 13 }