这里是写一个反转链表,利用头插法;
把之前的链表依次循环,插在新建的节点之后,他的新节点为这个节点的下个节点;
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode *pnew = new ListNode(-1);
ListNode *cur = pHead;
while(cur != NULL)
{
ListNode *post = cur->next;
cur->next = pnew->next;
pnew->next = cur;
cur = post;
}
return pnew->next;
}
};