剑指offer---反转链表

/*
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* cur=NULL;
        ListNode* pre=NULL;
        ListNode* nex=NULL;
        
        cur=pHead;
        nex=cur->next;
        
        while(1)
        {
            
            if(nex==NULL)
            {
                break;
            }
            
            pre=cur;
            cur=nex;
            nex=nex->next;
            nex->next=cur;
        }
        
        return cur;
    }
};
原文地址:https://www.cnblogs.com/159269lzm/p/7295204.html