LeetCode:反转链表
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* reverseList(struct ListNode* head){
if(head==NULL || head->next==NULL)
return head;
struct ListNode* pPre=head;
struct ListNode* pCur=head->next;
struct ListNode* pTmp=pCur;
head->next=NULL;
while(pTmp->next!=NULL)
{
pTmp=pTmp->next;
pCur->next=pPre;
pPre=pCur;
pCur=pTmp;
}
pCur->next=pPre;
return pCur;
}