inverser une liste doublement liée

public static DoublyLinkedListNode reverse(DoublyLinkedListNode node) {
        
        DoublyLinkedListNode newHead = null;
        do{
            // Last node is the new head now
            if(node.next == null){
                newHead = node;
            }
            
            DoublyLinkedListNode temp = node.prev;
            DoublyLinkedListNode nextNode  = null;
            
    // if node.next is null it means processing last node which is the new               //head
            if(node != null && node.next != null){
                nextNode = node.next;
                node.prev = nextNode;
            }
    // Creating prev next | next prev chaining 
            node.next = temp;
                
            if(node != null && nextNode != null)
                nextNode.prev = node;
            
            node = nextNode;
            
        }while(node != null);
        
        return newHead;
    }
Dr. iterations