反转链表

ListNode* reverseList(ListNode* head) {
        ListNode* tail=NULL;
        ListNode* front=head;
        ListNode* curr=NULL;
        //先令curr指向front,front移动下一个,curr的next指向tail实现反转
        //再移动tail
        while(front!=NULL){
            curr=front;
            front=front->next;
            curr->next=tail;
            tail=curr;
        }
        return tail;
    }
posted @ 2022-10-06 11:47  lwx_R  阅读(18)  评论(0)    收藏  举报