Reverse Linked List

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 }
View Code

 

posted @ 2015-06-25 12:16  Rosanne  阅读(166)  评论(0编辑  收藏  举报