Reverse 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) { if(head == NULL) return head; ListNode *pre = head,*next = pre->next,*temp; while(next){ temp = next->next; next->next = pre; pre = next; next = temp; } head->next = NULL; return pre; } };