剑指offer-反转链表
1 /* 2 struct ListNode { 3 int val; 4 struct ListNode *next; 5 ListNode(int x) : 6 val(x), next(NULL) { 7 } 8 };*/ 9 class Solution { 10 public: 11 ListNode* ReverseList(ListNode* pHead) { 12 ListNode* newpHead=NULL; 13 while(pHead!=NULL){ 14 ListNode* temp=pHead->next; 15 pHead->next=newpHead; 16 newpHead=pHead; 17 pHead=temp; 18 } 19 return newpHead; 20 } 21 };