翻转单链表

/* 
struct ListNode { 
    int val; 
    struct ListNode *next; 
    ListNode(int x) : 
            val(x), next(NULL) { 
    } 
};*/  
class Solution {  
public:  
    ListNode* ReverseList(ListNode* pHead) {  
        ListNode *dummy = new ListNode(-1);  
        ListNode *pCur = pHead;  
        ListNode *pNext = nullptr;  
        while(pCur)  
        {  
            pNext = pCur->next;  
            pCur->next= dummy->next;  
            dummy->next = pCur;  
            pCur = pNext;  
        }  
          
        return dummy->next;  
              
    }  
};  

 

posted on 2017-03-01 17:59  123_123  阅读(83)  评论(0编辑  收藏  举报