翻转单链表

/*
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;
        	
    }
};

你可能感兴趣的:(剑指offer)