Reverse Linked List

来源:互联网 发布:什么事windows原版系统 编辑:程序博客网 时间:2024/06/08 13:41
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) {
    if(head==NULL)
return NULL;
struct ListNode* Pre=NULL;
struct ListNode* pNode=head;
while(pNode!=NULL){
struct ListNode* pNext=pNode->next;
pNode->next=Pre;
Pre=pNode;
pNode=pNext;
}
return Pre;
}
0 0