Reverse a doubly linked list

/*
     * For your reference:
     *
     * DoublyLinkedListNode {
     *     int data;
     *     DoublyLinkedListNode next;
     *     DoublyLinkedListNode prev;
     * }
    */
    
    static DoublyLinkedListNode reverse(DoublyLinkedListNode head) {
        DoublyLinkedListNode current = head;
        DoublyLinkedListNode temp = null;
        //swap next and prev of all nodes of double linkedlist
        while (current!=null){
           temp = current.prev;
           current.prev = current.next;
           current.next = temp;
           current = current.prev;//move to last one
        }
        //check before changing head
        if (temp!=null){
            head = temp.prev;
        }
        return head;
    }
原文地址:https://www.cnblogs.com/johnnyzhao/p/12697371.html