输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* reverseList(struct ListNode* head) {
struct ListNode* H=head;
struct ListNode* P=H;
struct ListNode* NewH=NULL;
if(H==NULL)
return NULL;
while(P!=NULL)
{
struct ListNode* tmp=P->next;
P->next=NewH;
NewH=P;
P=tmp;
}
return NewH;
}