首页 > 其他分享 >反转链表

反转链表

时间:2022-10-06 11:56:37浏览次数:37  
标签:ListNode 反转 next 链表 tail front curr NULL

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;
    }

标签:ListNode,反转,next,链表,tail,front,curr,NULL
From: https://www.cnblogs.com/lwx11111/p/16757338.html

相关文章