标签:
Reverse a singly linked list.
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution{ public: ListNode* reverseList(ListNode* head){ ListNode* newHead = new ListNode(-1); ListNode* cur = head; while(cur){ ListNode* newHead_next = newHead->next; ListNode* next = cur->next; newHead->next = cur; cur->next = newHead_next; cur = next; } return newHead->next; } };
标签:
原文地址:http://www.cnblogs.com/wxquare/p/5928091.html