/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ #include <cstddef> class Solution { public: ListNode* ReverseList(ListNode* pHead) { if(pHead == NULL) return NULL; ListNode* p = pHead->next; ListNode* pre = pHead; while(p!=NULL){ //按照头插法将结点插入 //存储下一个结点 ListNode *t = p->next; p->next = pre; pre = p; p = t; } pHead->next = NULL; return pre; } };