/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
ListNode *rev_list = NULL;
ListNode *temp = NULL;
ListNode *cur = pHead;
while (cur != NULL) {
temp = cur -> next;
cur -> next = rev_list;
rev_list = cur;
cur = temp;
}
return rev_list;
}
};
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
if (pHead == NULL || pHead -> next == NULL) return pHead;
ListNode *new_list = ReverseList(pHead -> next);
pHead -> next -> next = pHead;
pHead -> next = NULL;
return new_list;
}
};