/*
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 *cur = pHead;
ListNode *temp = NULL;
while (cur != NULL){
temp = cur->next;//在这里暂存一下下一个指针
cur->next = pre;//把当前的值指向前一个值
pre = cur;//前一个值向后走一步
cur = temp;// 把下一个值付给当前的值
}
return pre;
}
};
来源:CSDN
作者:ttomchy
链接:https://blog.csdn.net/ttomchy/article/details/104678146