Reverse a doubly linked list

  • + 0 comments

    Only one line difference from the previous task (Scala):

        def reverse(llist: DoublyLinkedListNode): DoublyLinkedListNode = {
          def reverseNode(node: DoublyLinkedListNode, next: DoublyLinkedListNode): DoublyLinkedListNode =
            if (node == null) next
            else {
              val prev = node.next
              node.prev = prev
              node.next = next
              reverseNode(prev, node)
            }
          
          reverseNode(llist, null)
        }