方法一
思路就是:从原链表的头部一个一个取节点并插入到新链表的头部
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode* newh = NULL;
for(ListNode* p = pHead; p; )//p为工作指针
{
ListNode* tmp = p -> next;//temp保存下一个结点
p -> next = newh;
newh = p;
p = tmp;
}
return newh;
}
};