Reverse a doubly linked list

  • + 0 comments

    Java Solution:

        public static DoublyLinkedListNode reverse(DoublyLinkedListNode llist) {
            
            DoublyLinkedListNode curr = llist;
            DoublyLinkedListNode prev = null;
            
            while(curr != null){
                DoublyLinkedListNode next = curr.next;
                
                curr.next = prev;
                curr.prev = next;
                prev = curr;
                
                curr = next;
            }
        
            return prev;
        }