这道题可以定义一个新结点newhead,newhead指向NULL。此时遍历所给链表将遍历的每个结点头插到newhead上。
struct ListNode* reverseList(struct ListNode* head) {
struct ListNode* cur=head;
struct ListNode* newhead=NULL;
while(cur)
{
struct ListNode* next=cur->next;
//头插
cur->next=newhead;
newhead=cur;
cur=next;
}
return newhead;
}