206. Reverse Linked List(LeetCode)

Reverse a singly linked list.

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
    ListNode * pre=NULL;
        ListNode * current;
        while (head)
        {
            current = head;
            head = head->next;
            current->next=pre ;
            pre = current;
        }
        return pre;

    }
};
原文地址:https://www.cnblogs.com/wujufengyun/p/6834187.html