反转链表
输入一个链表,反转链表后,输出新链表的表头。
思路:定义一个pre,p,post,分别存p节点的前、当前、后的地址

/* 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* p=pHead; ListNode* post; while(p!=NULL) { post=p->next; p->next=pre; pre=p; p=post; } return pre;; } };