/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*
* C语言声明定义全局变量请加上static,防止重复定义
*
* C语言声明定义全局变量请加上static,防止重复定义
*/
/**
*
* @param pHead ListNode类
* @return ListNode类
*/
struct ListNode* ReverseList(struct ListNode* pHead ) {
if(pHead==NULL){
return pHead;
}
struct ListNode* p= pHead;
struct ListNode* pNext=p->next;
p->next=NULL;
struct ListNode* pForward=NULL;
//核心代码
while(pNext!=NULL){
pForward=p;
p=pNext;
pNext=p->next;
p->next=pForward;
}
p->next=pForward;
pHead=p;
return pHead;
}