/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
if(pHead==NULL) return NULL;
ListNode* pre = NULL;
ListNode* next = NULL;//保存链断前当前指针的下一结点
while(pHead!=NULL) {//当前结点不为空时执行
next = pHead->next;
pHead->next=pre;//反转
pre=pHead;
pHead=next;
}
return pre;
}
};