链表反转

 

ListNode* reversePrint(ListNode* head) {
        //*******************链表反转*********************
        ListNode* last = nullptr;
        ListNode* cur = head;
        while(cur != nullptr){
            ListNode* tmp = cur -> next;
            cur -> next = last;
            last = cur;
            cur = tmp;
        }
        return last;
}

 

posted @ 2021-01-06 20:56  zeroPatrick  阅读(36)  评论(0编辑  收藏  举报