/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ #include <cstdlib> class Solution { public: ListNode* ReverseList(ListNode* pHead) { if(pHead == NULL) { return NULL; } ListNode* prev = pHead; ListNode* cur = prev->next; ListNode* phead = NULL; while(prev) { prev->next = phead; phead = prev; prev = cur; if(cur) { cur = cur->next; } } return phead; } };